Two Pointer Algorithm Javascript Foreach Es6