const arr=[1,4,3,2,6,7,8]
function twoSum(arr, S) {
const sum = [];
for(let i = 0; i< arr.length; i++) {
for(let j = i+1; j < arr.length; j++) {
if( arr[i] + arr[j]==S) sum.push(arr[i],arr[j])
}
}
return sum
}
console.log(twoSum(arr,8))