Two Pointer Algorithm Javascript Foreach Continue Javascript