Skip to content

Instantly share code, notes, and snippets.

@kousherAlam
Created February 8, 2022 18:32
Show Gist options
  • Save kousherAlam/a899b8592ea088bec5823af29efdce89 to your computer and use it in GitHub Desktop.
Save kousherAlam/a899b8592ea088bec5823af29efdce89 to your computer and use it in GitHub Desktop.
function check(numbers:number[], value: number): number[] {
const needMap:any = {};
const result: number[] = [];
let round = 0;
numbers.every((n, index) => {
round ++;
if(needMap[n] > -1) {
result.push(...[numbers[needMap[n]], n]);
return false;
} else {
const needed = value - n ;
needMap[needed] = index;
}
return true;
});
console.log(`totoal round ${round} of ${numbers.length}`);
return result;
}
console.log(check([11,2, 5, 1, 4,5,2,302, 7, 3], 10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment