Two Sum Algorithm Javascript Substring Function