Skip to content

Instantly share code, notes, and snippets.

@svahora
Last active August 29, 2015 14:27
Show Gist options
  • Save svahora/0787534a20886beab3cc to your computer and use it in GitHub Desktop.
Save svahora/0787534a20886beab3cc to your computer and use it in GitHub Desktop.
function pairwise(arr, arg) {
var newArg = 0;
for(x=0; x<arr.length ; x++) {
var a = arr[x];
if(x+1 === arr.length) {
break;
} else {
for(y=x+1; y<arr.length; y++) {
var b = arr[y];
if(a+b === arg) {
newArg += (x+y);
arr[x]=''; a='';
arr[y]=''; b='';
}
}
}
}
return newArg;
}
console.log(pairwise([1,4,2,3,0,5], 7)); console.log("is " + 11);
console.log(pairwise([1, 3, 2, 4], 4)); console.log("is " + 1);
console.log(pairwise([1,1,1], 2)); console.log("is " + 1);
console.log(pairwise([0, 0, 0, 0, 1, 1],1)); console.log("is " + 10);
console.log(pairwise([], 100));console.log("is " + 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment