Last active
August 29, 2015 14:24
-
-
Save ronihcohen/8a75c8176602e31622f5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 pairwise(arr, arg) { | |
var markerArr = []; | |
for (i=0;i<=arr.length-1;i++){ | |
for (x=i+1;x<=arr.length-1;x++){ | |
if ( !markerArr[x] && !markerArr[i]){ | |
if (arr[x]+arr[i]==arg){ | |
markerArr[x] = markerArr[i]= true; | |
} | |
} | |
} | |
} | |
console.log (markerArr); | |
return markerArr.reduce(function(previousValue, currentValue, index, array) { | |
if (currentValue){ | |
return previousValue + index; | |
} | |
},0); | |
} | |
pairwise([1,1,1], 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment