const pipeAsync = (...fns) => async (value) => {
console.log('fns', fns)
return await fns.reduce((sum, fn) => {
if (typeof fn !== 'function') {
throw new TypeError('fn is not a function');
}
return Promise.resolve(sum).then(fn);
const transactions = [
{
merchantName: 'Netflix',
amount: 5.99,
currency: 'GBP',
bookingDateTime: '2020-01-01T19:33:23.473Z',
},
{
merchantName: 'Petfood Co',
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 albums = [ | |
{ | |
artist: "Pearl Jam", | |
album: "Ten", | |
year: "1991" | |
}, | |
{ | |
artist: "Pearl Jam", | |
album: "Yield", | |
year: "1998" |
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
{ | |
1991: [ | |
{ | |
{ | |
artist: 'Pearl Jam', | |
album: 'Ten', | |
year: '1991', | |
}, | |
{ | |
artist: 'Soundgarden', |
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
{ | |
'Pearl Jam': [ | |
{ | |
artist: 'Pearl Jam', | |
album: 'Ten', | |
year: '1991', | |
}, | |
{ | |
artist: 'Pearl Jam', | |
album: 'Yield', |
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
function groupBy(key) { | |
return function group(array) { | |
return array.reduce((acc, obj) => { | |
const property = obj[key]; | |
acc[property] = acc[property] || []; | |
acc[property].push(obj); | |
return acc; | |
}, {}); | |
}; | |
} |
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 property = obj[key]; | |
// obj[key] here will be '1991'. | |
acc[property] = acc[property] || []; | |
// At this point acc['1991'] doesn't yet exist, so it will be an empty array. This step is important as it checks if acc['1991'] exists, and if not, creates it and assigns a value of an empty array. | |
acc[property].push(obj); | |
// Here, all we're doing is pushing our object into the right group |
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
{ | |
"window.zoomLevel": 0, | |
"terminal.integrated.shell.osx": "zsh", | |
"editor.fontFamily": "Fira Code", | |
"editor.fontLigatures": true, | |
"editor.minimap.enabled": false, | |
"workbench.iconTheme": "material-icon-theme", | |
"workbench.editor.enablePreview": false, | |
"editor.tabSize": 2, | |
"editor.rulers": [100], |