Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created September 3, 2017 02:18
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 JosePedroDias/383562b9d3b2beffe8cb057b42821bbf to your computer and use it in GitHub Desktop.
Save JosePedroDias/383562b9d3b2beffe8cb057b42821bbf to your computer and use it in GitHub Desktop.
jscrunch by hand
// 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
@JosePedroDias
Copy link
Author

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