Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A collection of weepingly beautiful javascript written by other people. For me to open late at night and admire secretly.
// Pull a secret string out of ordered triplets
// https://www.codewars.com/kata/recover-a-secret-string-from-random-triplets/train/javascript
// https://www.codewars.com/kata/53f40dff5f9d31b813000774/solutions/javascript
// @LesRamer
var recoverSecret = function(triplets) {
for(var [first] of triplets)
{
if (triplets.every(tuple => tuple.indexOf(first) <= 0))
{
triplets.filter(([item]) => item == first).forEach(tuple => tuple.shift());
return first + recoverSecret(triplets.filter(tuple => tuple.length > 0));
}
}
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.