Skip to content

Instantly share code, notes, and snippets.

@walmik
Created October 29, 2013 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walmik/7208430 to your computer and use it in GitHub Desktop.
Save walmik/7208430 to your computer and use it in GitHub Desktop.
Given an array of integers and an integer return true if any 2 integers of the array add up to a number equal to the integer For example: fn ( [2,1,3,4], 4 ); should return true
function doubleCheck(arr, intgr) {
var bool = false;
arr = arr.sort(function(a,b) {return a-b;});
console.log(arr);
while(arr.length) {
var num = arr.shift();
for(var i=0; i<arr.length; i++) {
console.log('iteration' + arr[i]);
if(num + arr[i] === intgr) {
return true;
}
}
}
return bool;
}
if(doubleCheck([2,7,5,6,23,12,11,8,3,4], 5)) console.log('ok');
else console.log('ko');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment