Skip to content

Instantly share code, notes, and snippets.

@ronihcohen
Last active August 29, 2015 14:24
Show Gist options
  • Save ronihcohen/8a75c8176602e31622f5 to your computer and use it in GitHub Desktop.
Save ronihcohen/8a75c8176602e31622f5 to your computer and use it in GitHub Desktop.
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