- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwoSum.js
More file actions
Latest commit
25 lines (20 loc) · 551 Bytes
/
Copy pathtwoSum.js
File metadata and controls
25 lines (20 loc) · 551 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
lettwoSum=(myArray,sum,cb)=>{
lettwoSumArr=[];
console.log(myArray);
for(leti=0;i<myArray.length;i++){
for(letj=i+1;j<myArray.length;j++){
if(i==j)continue;
if(myArray[i]+myArray[j]==sum){
letnewArray=[myArray[i],myArray[j]];
twoSumArr.push(newArray);
}
}
}
cb(null,twoSumArr);
};
twoSum([1,6,4,5,3,3],7,(err,twoSumArray)=>{
if(err){
}else{
console.log(twoSumArray);
}
});