Last active
August 29, 2015 14:13
-
-
Save juliankrispel/d1053d393c181a0a2b78 to your computer and use it in GitHub Desktop.
rainforest test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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