This file contains hidden or 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
// 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] |
This file contains hidden or 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 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})` |
This file contains hidden or 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
// 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 [ |
This file contains hidden or 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 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 }; | |
/* | |
=> { |
This file contains hidden or 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 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; | |
This file contains hidden or 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 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"}, | |
{ title: "London Calling", artist: "The Clash", type: "LP", lengthSec: 3903, released: "1979"}, | |
{ title: "Ramones", artist: "Ramones", type: "LP", lengthSec: 1755, released: "1976"}, | |
...etc | |
]; | |
const removeIndexes = [1, 2]; | |
records.reduceRight((acc, item, idx) => { |
This file contains hidden or 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 apiResponse = [ | |
{first: 'Bob', favorite: 'The Clash'}, | |
{first: 'Linda', favorite: 'Ramones'}, | |
{first: 'Amy', favorite: 'The Clash'}, | |
]; | |
const friendConstants = ['Bob', 'Amy', 'James', 'Tiffany', 'Linda']; | |
friendConstants.reduce((acc, friend, idx, orgArray) => ({ | |
// Check for friend in apiResponse | |
// if there pull them out otherwise we create a default objecct |
This file contains hidden or 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
// Materialize | |
<Input | |
s=number // ########## | |
m=number // Media query sizes | |
l=number // ########## | |
children=node | |
className=string | |
label=node | |
error=string | |
success=string |
OlderNewer