Skip to content

Instantly share code, notes, and snippets.

Example of functional piping

  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',
const albums = [
{
artist: "Pearl Jam",
album: "Ten",
year: "1991"
},
{
artist: "Pearl Jam",
album: "Yield",
year: "1998"
{
1991: [
{
{
artist: 'Pearl Jam',
album: 'Ten',
year: '1991',
},
{
artist: 'Soundgarden',
{
'Pearl Jam': [
{
artist: 'Pearl Jam',
album: 'Ten',
year: '1991',
},
{
artist: 'Pearl Jam',
album: 'Yield',
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;
}, {});
};
}
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
@nkhil
nkhil / mongodb_cheat_sheet.md
Last active May 31, 2020 19:35 — forked from bradtraversy/mongodb_cheat_sheet.md
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

{
"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],

Quick reference for using node-scheduler

Every 5 seconds

const x = schedule.scheduleJob('*/5 * * * * *', function() {
  console.log('The answer to life, the universe, and everything!');
});