Last active
September 13, 2016 05:09
-
-
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.
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
// 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