// Given an array of integers,
//write a JavaScript function that finds and prints
//all pairs of numbers in the array that sum up to 17.
//Optimize the function to have a time complexity of O(n).
const newArr = [1,2,13,4,15,18,-1]
const checkPairs = (arr, sum) => {
const seen = {}
for(value of arr){
const currentNumber = value
const toCheckFromStoredNo = sum - currentNumber
if(seen[toCheckFromStoredNo]){
console.log("pairs are", toCheckFromStoredNo, currentNumber)
}
seen[currentNumber] = true
}
}
checkPairs(newArr, 17)
To embed this project on your website, copy the following code and paste it into your website's HTML: