Skip to content

Instantly share code, notes, and snippets.

@nicholasaiello
Last active October 9, 2017 19:36
Show Gist options
  • Save nicholasaiello/297d72ffda8b48e4fea0e16011d1faf5 to your computer and use it in GitHub Desktop.
Save nicholasaiello/297d72ffda8b48e4fea0e16011d1faf5 to your computer and use it in GitHub Desktop.
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