algorithms in javascript