Two Pointer Algorithm Javascript Substring Function In Sql