Created
October 29, 2013 02:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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