review Javascript algorithm in CoderByte.com (hard)