Skip to content

Instantly share code, notes, and snippets.

@StevenACoffman
Forked from roman01la/index.js
Last active January 27, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenACoffman/0a29ad508f12f927bedd to your computer and use it in GitHub Desktop.
Save StevenACoffman/0a29ad508f12f927bedd to your computer and use it in GitHub Desktop.
Broken but not sure why
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