Last active
October 9, 2017 19:36
-
-
Save nicholasaiello/297d72ffda8b48e4fea0e16011d1faf5 to your computer and use it in GitHub Desktop.
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
const input = "who tried never Made anything a A Mistake never New Person.", | |
stripPunctuation = (str) => str.replace(/[\.\,\?\-\_\!]/, ''), | |
isLowerCase = (str) => !(str.charCodeAt(0) >= 65 && str.charCodeAt(0) <= 90), | |
format = (arr) => arr.reverse().join(' ') | |
const sortFn = (a, b) => { | |
if (isLowerCase(a) && isLowerCase(b)) { | |
return a.localeCompare(b) * -1; | |
} else if (isLowerCase(a)) { | |
return 1; | |
} else { | |
return b.localeCompare(a) * -1; | |
} | |
}; | |
const curry = (str) => | |
parse => | |
fn => | |
fn => | |
format => ( | |
format( | |
parse(str).split(' ').sort(fn).sort(fn) | |
) | |
) | |
const result = curry(input)(stripPunctuation)(sortFn)(sortFn)(format); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment