Created
September 3, 2017 02:18
-
-
Save JosePedroDias/383562b9d3b2beffe8cb057b42821bbf to your computer and use it in GitHub Desktop.
jscrunch by hand
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
// HAND MADE JSCRUNCH | |
ORIGINAL_CODE = '-que tal está isso asd? quero que fiques comigo querida asd.' | |
// naive approach | |
// 1) replace 'que' with '' | |
_ = '- tal está isso asd? ro fis comigo rida asd.' | |
_.split('').join('que') | |
// 2) replace 'asd' with '' | |
_ = '- tal está isso ? ro fis comigo rida .' | |
_ | |
.split('').join('que') | |
.split('').join('asd') | |
// Now let's apply the jscrunch algorithm: | |
// For every character in $ it is splitting _ on the character, | |
// using with to make the resulting array the scope. | |
// Then joining the pieces using the last piece and reassigning to _ | |
// 3 lets apply it, replacing each word at a time... | |
// 3a) | |
_='-que tal está isso asd? quero que fiques comigo querida asd.' | |
// 3b) | |
_='- tal está isso asd? ro fis comigo rida asd.que' | |
for (Y in $='') with (_.split($[Y])) | |
_ = join(pop()) | |
// 3c) | |
_='- tal está isso ? ro fis comigo rida .queasd' | |
for (Y in $='') with (_.split($[Y])) | |
_ = join(pop()) | |
// then eval the expanded _ var :D | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on