Sedgewick Algorithms in java script