Skip to content

Instantly share code, notes, and snippets.

@SimplGy
Last active September 13, 2016 05:09
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 SimplGy/3dbe10063a3cf4e23c56ae9e2d952395 to your computer and use it in GitHub Desktop.
Save SimplGy/3dbe10063a3cf4e23c56ae9e2d952395 to your computer and use it in GitHub Desktop.
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