-
-
Save StevenACoffman/0a29ad508f12f927bedd to your computer and use it in GitHub Desktop.
Broken but not sure why
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 mapping = (f) => (reducing) => (result, input, index) => reducing(result, f(input, index)); | |
const filtering = (predicate) => (reducing) => (result, input, index) => predicate(input) ? reducing(result, input, index) : result; | |
const ALPHABET = 'abcdefghijklmnopqrstuvwxyz'.split(''); | |
const NUMBERS = '0123456789'.split(''); | |
const isAlphaNumeric = (letter) => ALPHABET.indexOf(letter) !== -1 || NUMBERS.indexOf(letter) !== -1; | |
const periodicallyPad = (current, index) => index !== 0 && index % 5 === 0 ? ' ' + current : current; | |
const concatenate = (xs, x, index) => xs.concat(x); | |
const result = 'I AM SO EXCITED ABOUT TRANSDUCERS'.toLowerCase().split('') | |
.reduce(filtering(isAlphaNumeric)((xs, x) => xs.concat(x)), []) | |
.reduce(mapping(periodicallyPad)((xs, x) => xs.concat(x)), []) | |
.join(''); | |
console.log(result); | |
const incorrectResult = 'I AM SO EXCITED ABOUT TRANSDUCERS'.toLowerCase().split('') | |
.reduce(filtering(isAlphaNumeric)(mapping(periodicallyPad))((xs, x) => xs.concat(x)), []) | |
.join(''); | |
console.log(incorrectResult); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment