Skip to content

Instantly share code, notes, and snippets.

View jasonbellamy's full-sized avatar

Jason Bellamy jasonbellamy

View GitHub Profile
var xs = {
template: [
{template: 'one', dest: 'two'},
{template: 'one', dest: 'two'}
],
copy: [
{template: 'one', dest: 'two'},
{template: 'one', dest: 'two'}
]
};
const generator = (x, y = x) => {
return {x: `_${x}`, y};
};
const xs = [1, 2, 3, 4, 5];
const [ x ] = xs.slice(-1); //=> 5
@jasonbellamy
jasonbellamy / tail-with-index-and-length.js
Last active September 3, 2016 16:25
Get the value of the last item in an array using the arrays index and length
const xs = [1, 2, 3, 4, 5];
const x = xs[xs.length - 1]; //=> 5
@jasonbellamy
jasonbellamy / tail-with-pop.js
Last active September 3, 2016 16:25
Get the value of the last item in an array using the arrays pop method
const xs = [1, 2, 3, 4, 5];
const x = xs.pop(); //=> 5
@jasonbellamy
jasonbellamy / tail-with-reverse.js
Created September 3, 2016 16:31
Get the value of the last item in an array using the arrays .reverse() method
const xs = [1, 2, 3, 4, 5];
const [ x ] = xs.reverse() //=> 5
@jasonbellamy
jasonbellamy / tail-with-reverse-shift.js
Created September 3, 2016 16:41
Get the value of the last item in an array using the arrays .reverse() method
const xs = [1, 2, 3, 4, 5];
const x = xs.reverse().shift() //=> 5
@jasonbellamy
jasonbellamy / tail-with-filter-and-index-and-length.js
Created September 3, 2016 19:39
Get the value of the last item in an array using desctructing and the arrays .filter(), index, and length
const xs = [1, 2, 3, 4, 5];
const [ x ] = xs.filter((x, index, array) => {
return index === array.length);
}); // => 5
@jasonbellamy
jasonbellamy / compose.js
Created October 18, 2016 02:36
2 different implementations of compose
const compose = (...rest) => (
(z) => rest.reverse().reduce((x, y) => y(x), z)
);
const compose2 = (fn, ...rest) => (
(rest.length === 0) ? fn :(z) => compose2(...rest)(fn(z))
);
@jasonbellamy
jasonbellamy / length.js
Created October 19, 2016 01:56
recursive implementation of length
const length = ([head, ...tail]) => (
(head === void 0) ? 0 : 1 + length(tail)
);