Two Pointer Algorithm Javascript Substring From Right