Skip to content

Instantly share code, notes, and snippets.

@elis
Created March 1, 2015 20:28
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 elis/0b17702c4c38056aa9f4 to your computer and use it in GitHub Desktop.
Save elis/0b17702c4c38056aa9f4 to your computer and use it in GitHub Desktop.
ES6 expr
let dat = (y,x) => (console.log('x', x, 'y', y) && false) || (x+y);
console.log(dat(15,30));
// let outer = (word) => ((logger = (letter) => for (i=0; i<letter.length; ++i) console.log(letter.charCodeAt(i))) && false) || (logger(word));
// outer('It\'s a test'); // Fails
let arrays = (word) => Array.prototype.forEach.call(word, (letter, pos) => console.log(letter, word.charCodeAt(pos)))
// arrays('this is testing'); // Works
let each = (ar, fn) => Array.prototype.forEach.call(ar, fn);
let codes = (word) => each(word, (letter, pos) => console.log(letter, word.charCodeAt(pos)));
// console.log(codes('What\'s the code for this string?')); // Works
let pad = (str, len, it) => (new Array(len-(str.toString().length-1)).join(it)) + str;
console.log(pad('eli', 6, '+')); // Works
let codes2 = (word) => each(word, (letter, pos) => console.log(pad(pos, 2, '0'), "'" + letter + "'", pad(word.charCodeAt(pos), 4, ' ')));
// codes2('hey there'); // Works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment