Skip to content

Instantly share code, notes, and snippets.

@juliankrispel
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliankrispel/d1053d393c181a0a2b78 to your computer and use it in GitHub Desktop.
Save juliankrispel/d1053d393c181a0a2b78 to your computer and use it in GitHub Desktop.
rainforest test
// Only works on letsrevolutionizetesting.com/challenge since CORS
// is disabled and jquery is included on that page
var getRecursive = function(url){
return $.ajax({url: url, dataType: 'json'})
.then(function(res){
if(res.hasOwnProperty('follow')){
return getRecursive(res.follow);
}else{
return res;
}
});
};
getRecursive('http://letsrevolutionizetesting.com/challenge')
.then(function(res){
console.log(res)
});
// Given an array of integers, return all the unique pairs of numbers
// in that array that adds up to 100.
//
// Input: [1, 27, 50, 49, 51, 99, 51, 51]
// Output: [[1, 99], [49, 51]]
var sortByValue = function(a, b){
return a > b;
};
var uniquePairs = function(input){
var possibleCombinations = {};
input.forEach(function(int, i){
input.forEach(function(int2, i2){
var combination = [int, int2].sort(sortByValue);
var combinationString = combination.join(',');
if(possibleCombinations[combinationString] === undefined &&
int + int2 === 100 &&
i !== i2){
possibleCombinations[combinationString] = combination;
}
});
});
return possibleCombinations;
};
//test
console.log(uniquePairs([1, 27, 50, 49, 51, 99, 51, 51]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment