Two Sum Algorithm Javascript Substring Method