RLDatix interview question

solve an basic algorithm in JavaScript