Given an unordered array of integers and a value sum, return true if any two items may be added such that they equal the value of sum . Otherwise, return false.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
constfindSum = (arr, val) => { let searchValues = newSet(); searchValues.add(val - arr[0]); for (let i = 1, length = arr.length; i < length; i++) { let searchVal = val - arr[i]; if (searchValues.has(arr[i])) { returntrue; } else { searchValues.add(searchVal); } }; returnfalse; };