Skip to content

Instantly share code, notes, and snippets.

@fdjones
Last active March 31, 2017 17:09
Show Gist options
  • Save fdjones/41625719b9275c11989e155f6ae90258 to your computer and use it in GitHub Desktop.
Save fdjones/41625719b9275c11989e155f6ae90258 to your computer and use it in GitHub Desktop.
function sumPairs(values, target) { // or "sum_pairs", but camelCase is the JS convention
var limit = values.length,
result,
i, j;
for(i = 0 ; i < limit ; i++) {
for(j = i+1 ; j < limit ; j++) {
if(values[i] + values[j] == target) {
result = [values[i], values[j]];
limit = j;
}
}
}
return result;
}
sum_pairs([10,5,2,3,7,5], 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment