Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
explaining my js
// Set the variables R, C, and U equal to 'replace', 'charAt', and 'toUpperCase'
// Replace searches a string and replaces characters
// charAt finds the char at a certain position
// toUpperCase makes things uppercase
// alert causes an on-screen pop-up, needed for this competition because I have to write to STDOUT
// a[R] means the same as a.replace() see variable `R` above
// This regexp looks for any of those words (COMMA, SEMICOLON, etc) that match the pattern "^WORD"
// Because I'm using replace() I can declare the replacement as a function
// In order to do so, I'm using ECMA 6's arrow functions
// Arrow functions follow the syntax of:
([param] [, param]) => {
param => expression
// So, I'm essentially saying, a.replace([regexp], function(args) {if (a) { do things } else if { do more things} })
,((m,_,a,b,c,d,e,f,g,h,i,j)=>a?",":b?";":c?":":d?".":e?"!":f?"-":g?"-h-":h?"-e-":i?' "':'" '))
// This is the same thing, except I'm using different regexps
// These say, match any string that's something like "[space][punctuation]"
// I have to list all these in order because they're being mapped to my arguments
// So the (\.) is mapped to argument 'v', hence the v?"."
// Again, same as above except this time I'm taking the [C]haracter at position (0) and making it [U]ppercase() then taking the rest of the string and tacking it on to the end of that character
// Nearly the same... figure it out >:)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.