Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created October 14, 2011 15:03
Show Gist options
  • Select an option

  • Save cowboy/1287364 to your computer and use it in GitHub Desktop.

Select an option

Save cowboy/1287364 to your computer and use it in GitHub Desktop.
[
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
" ```````` `.::::-.",
" MMMMMMM+ /ymMMMMMMMMMms:",
" MMMMMMM+ +NMMMMMMMMMMMMMMMd:",
" MMMMMMM+ sMMMMMMMMNNNMMMMMMMN:",
" MMMMMMM+ :MMMMMMMo` .oNMNy/`",
" MMMMMMM+ oMMMMMMd .:",
" MMMMMMM+ /MMMMMMMo`",
" MMMMMMM+ dMMMMMMMMho:`",
" MMMMMMM+ `hMMMMMMMMMMMmy/.",
" MMMMMMM+ :hMMMMMMMMMMMMMmo`",
" MMMMMMM+ `/ymMMMMMMMMMMMMs`",
" MMMMMMM+ `:ohNMMMMMMMMd`",
" MMMMMMM+ :yMMMMMMMs",
" . MMMMMMM/ `// yMMMMMMd",
" `/yNM+ :MMMMMMM- .+dMMMh- `dMMMMMMh",
"-dMMMMMMmo//+yMMMMMMMd :MMMMMMMMmy+///oyNMMMMMMM:",
" oMMMMMMMMMMMMMMMMMMm. .hMMMMMMMMMMMMMMMMMMMMN/",
" .sNMMMMMMMMMMMMMNo` -sNMMMMMMMMMMMMMMMNo`",
" :oydmNNNmdyo- ./shdmNNNmdhs+-",
"",
""
].join("\n").replace(/([\s\S])\1+/g, function(str, char) {
return str.length + char;
}).replace(/\n/g, '\\n');
// Unminifed:
("17\n15 8`12 `.4:-.\n15 7M+9 /ym9Mms:\n15 7M+7 +N15Md:\n15 7M+6 s8M3N7MN:\n" +
"15 7M+5 :7Mo`3 .oNMNy/`\n15 7M+5 o6Md7 .:\n15 7M+5 /7Mo`\n15 7M+6 d8Mho:`\n" +
"15 7M+6 `h11Mmy/.\n15 7M+8 :h13Mmo`\n15 7M+10 `/ym12Ms`\n15 7M+14 `:ohN8Md`" +
"\n15 7M+19 :y7Ms\n6 .8 7M/7 `2/11 y6Md\n2 `/yNM+6 :7M-4 .+d3Mh-8 `d6Mh\n-d" +
"6Mmo2/+y7Md4 :8Mmy+3/oyN7M:\n o18Mm.5 .h20MN/\n2 .sN13MNo`8 -sN15MNo`\n5 :o" +
"ydm3Nmdyo-14 ./shdm3Nmdhs+-2\n").replace(/(\d+)([\s\S])/g, function(_, n, s) {
return Array(+n + 1).join(s);
})
"17\n15 8`12 `.4:-.\n15 7M+9 /ym9Mms:\n15 7M+7 +N15Md:\n15 7M+6 s8M3N7MN:\n15 7M+5 :7Mo`3 .oNMNy/`\n15 7M+5 o6Md7 .:\n15 7M+5 /7Mo`\n15 7M+6 d8Mho:`\n15 7M+6 `h11Mmy/.\n15 7M+8 :h13Mmo`\n15 7M+10 `/ym12Ms`\n15 7M+14 `:ohN8Md`\n15 7M+19 :y7Ms\n6 .8 7M/7 `2/11 y6Md\n2 `/yNM+6 :7M-4 .+d3Mh-8 `d6Mh\n-d6Mmo2/+y7Md4 :8Mmy+3/oyN7M:\n o18Mm.5 .h20MN/\n2 .sN13MNo`8 -sN15MNo`\n5 :oydm3Nmdyo-14 ./shdm3Nmdhs+-3\n".replace(/(\d+)([\s\S])/g,function(_,n,s){return Array(+n+1).join(s)});
@Kambfhase
Copy link
Copy Markdown

you totally wasted one byte there: +n+1 can be reduced to -~n.

@cowboy
Copy link
Copy Markdown
Author

cowboy commented Oct 14, 2011

Awesome.

@mathiasbynens
Copy link
Copy Markdown

If IE < 9 support is not an issue, you could save some bytes by using [^] instead of [\s\S].

Performance test case: http://jsperf.com/match-any-char-regex

@cowboy
Copy link
Copy Markdown
Author

cowboy commented Oct 23, 2011

Is [^] matching all characters a bug?

@mathiasbynens
Copy link
Copy Markdown

It’s a feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment