Skip to content

Instantly share code, notes, and snippets.

@brandonbarringer
Created March 22, 2016 20:58
Show Gist options
  • Save brandonbarringer/0830ce84253f8f04ce89 to your computer and use it in GitHub Desktop.
Save brandonbarringer/0830ce84253f8f04ce89 to your computer and use it in GitHub Desktop.
Expander
/*
You are given a string s composed of letters and numbers, which was compressed with some algorithm.
Every letter in s is followed by a number (possibly with leading zeros),
which represents the number of times this letter occurs consecutively. For example, "aaaaaaaabbbbbbcc"
would be given as "a8b6c2".
*/
Expand_It = (s, k) => s.split(/(\d+|\D+)/g).filter(n => !!n).map( (v, i, a) => v.repeat( a[i+1] ) ).sort().join("")[k-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment