Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

find if two elements in array sum to given integer js

function twoSum(arr, S) {
 const sum = [];
  for(let i = 0; i< arr.length; i++) {
    for(let j = i+1;  j < arr.length; j++) {
      if(S == arr[i] + arr[j]) sum.push([arr[i],arr[j]])
    }
  }
 return sum
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #elements #array #sum #integer #js
ADD COMMENT
Topic
Name
4+7 =