Skip to content

Instantly share code, notes, and snippets.

@AungMyoKyaw
Last active April 27, 2016 11:58
Show Gist options
  • Save AungMyoKyaw/68966c38e070a074021334ab506ccdde to your computer and use it in GitHub Desktop.
Save AungMyoKyaw/68966c38e070a074021334ab506ccdde to your computer and use it in GitHub Desktop.
Pairwise Free Code Camp
function pairwise(arr, arg) {
var amk=[];
if(arr.length===0){
return 0;
}
arr.forEach(function(element,index){
if(isNaN(element)===false){
var tofind=arg-element;
var indexpos=arr.indexOf(tofind);
if(indexpos!==-1 && index!==indexpos){
amk.push(index);
amk.push(indexpos);
arr[index]="done";
arr[indexpos]="done";
}
}
});
return amk.reduce(function(a,b){return a+b;});
}
//pairwise([1,4,2,3,0,5], 7);
pairwise([], 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment