Preview:
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))
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter