review Javascript Algorithm in CoderByte(medium, hard)