Last active
November 8, 2017 20:00
-
-
Save Anmo/b0d4df915bac26b96c7d1422643af7cd to your computer and use it in GitHub Desktop.
My summition at OLX websummit challenge
This file contains hidden or 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
var oneLiner = (script, { | |
splitter = /( +|\n+|\t+|\/|'|")/g, | |
varDeclaration = /^(var|const|let)$/, | |
testRegex = '/', | |
testString = /'|"/, | |
filterer = /[ \n\t]+/ | |
} = {}, prev = '', insideRegex = false, insideString = false) => | |
script | |
.split(splitter) | |
.map((_) => | |
varDeclaration.test(prev) || | |
insideRegex || | |
insideString || | |
!filterer.test(_) | |
? prev = ( | |
!insideString && _ === testRegex && (!prev.endsWith('\\') || prev.endsWith('\\\\')) | |
? insideRegex = !insideRegex | |
: !insideRegex && testString.test(_) && (!prev.endsWith('\\') || prev.endsWith('\\\\')) | |
? insideString = !insideString | |
: false | |
) && | |
false || | |
_ | |
: insideString || insideRegex ? _ : '') | |
.join('') |
This file contains hidden or 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
var oneLiner=(script,{splitter=/( +|\n+|\t+|\/|'|")/g,varDeclaration=/^(var|const|let)$/,testRegex='/',testString=/'|"/,filterer=/[ \n\t]+/}={},prev='',insideRegex=false,insideString=false)=>script.split(splitter).map((_)=>varDeclaration.test(prev)||insideRegex||insideString||!filterer.test(_)?prev=(!insideString&&_===testRegex&&(!prev.endsWith('\\')||prev.endsWith('\\\\'))?insideRegex=!insideRegex:!insideRegex&&testString.test(_)&&(!prev.endsWith('\\')||prev.endsWith('\\\\'))?insideString=!insideString:false)&&false||_:insideString||insideRegex?_:'').join('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment