Skip to content

Instantly share code, notes, and snippets.

const records = [
{ title: "The Clash", artist: "The Clash", type: "LP", lengthSec: 2220, released: "1977"},
{ title: "Rocket to Russia", artist: "Ramones", type: "LP", lengthSec: 1906, released: "1977"},
...etc
];
// es5
const way = records.reduce((acc, record) => {
acc[`${record.title} - ${record.artist}`] = record;
const records = [
{ title: "The Clash", artist: "The Clash", type: "LP", lengthSec: 2220, released: "1977"},
{ title: "Rocket to Russia", artist: "Ramones", type: "LP", lengthSec: 1906, released: "1977"},
...etc
];
const wayOne = Object.assign({}, records);
const wayTwo = { ...records };
/*
=> {
// item is named record for easily knowing what
// we're operating on
records.reduce((acc, record) => {
// Recored is not longer than 60 mins
// return acc as is, doing nothing with record (filter)
if (record.lengthSec > (60 * 60)) return acc;
// Destructure acc into new array
// Destructure record into new object and add display prop
return [
const records = [
{ title: "The Clash", artist: "The Clash", type: "LP", lengthSec: 2220, released: "1977"},
{ title: "Rocket to Russia", artist: "Ramones", type: "LP", lengthSec: 1906, released: "1977"},
...etc
];
records.filter(record => record.lengthSec > (60 * 60))
.map(record => ({
...record,
['display']: `${record.artist} - ${record.title} (${record.released})`
// Takes an `array` a `callback` and an `initialValue`
// uses an inner `recursiveFn` to iterate over all array values
// calling the `callback` on each one
const reduce = (orgArray, callback, initialValue) => (
(function recursiveFn(idx, acc) {
// base condition to end looping
if (idx > orgArray.length - 1) return acc;
// calculate and pass values to next step
return recursiveFn(idx + 1, callback(acc, orgArray[idx], idx, orgArray))
// start the iterations at orgArray[0]
@bryzettler
bryzettler / iterm2-solarized.md
Created May 24, 2016 16:15 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + oh my zsh + solarized + Meslo powerline font (OSX)

Solarized