began writing a javascript algorithm.