Two Sum Algorithm in JavaScript