using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies
This file contains 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 toNewGroup = (field) => (result, obj) => ({ | |
...result, | |
[obj[field]]: [...(result[obj[field]] || []), obj] | |
}) | |
const groups = list.reduce(toNewGroup("level"), {}) |
This file contains 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 toNewGroup = (field) => (result, obj) => { | |
result[obj[field]] = (!result[obj[field]]) | |
? [obj] | |
: [...result[obj[field]], obj] | |
return result | |
} | |
const groups = list.reduce(toNewGroup("level"), {}) | |
console.log(groups) |
This file contains 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 toNewGroup = (field) => (result, obj) => { | |
result[field] = (!result[field]) | |
? [obj] | |
: [...result[field], obj] | |
return result | |
} | |
const groups = list.reduce(toNewGroup("level"), {}) | |
console.log(groups) |
This file contains 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
{ senior: | |
[ { id: 1, | |
name: 'Suissa', | |
active: true, | |
level: 'senior', | |
tags: [Array] }, | |
{ id: 2, | |
name: 'Bella', | |
active: true, | |
level: 'senior', |
This file contains 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 plenos = list.filter(toGroup("level", "pleno")) | |
console.log({plenos}) | |
/** | |
{ plenos: | |
[ { id: 4, | |
name: 'John', | |
level: 'pleno', | |
active: false, | |
tags: [Array] } ] } |
This file contains 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 toGroup = (field, value) => (obj) => | |
obj[field] === value | |
const filtered = list.filter(toGroup("level", "senior")) | |
console.log({filtered}) | |
/** | |
{ filtered: | |
[ { id: 1, | |
name: 'Suissa', |
This file contains 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 obj1 = { | |
id: 1, | |
name: "Suissa", | |
active: true, | |
level: "senior", | |
tags: [ | |
"teacher", | |
"dev", | |
"js" | |
] |
This file contains 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
import nodemailer from 'nodemailer'; | |
const transporter = nodemailer.createTransport({ | |
host: 'smtp.gmail.com', | |
port: 465, | |
secure: true, // use SSL | |
auth: { | |
user: "mailer@gmail.com", | |
pass: "senha" | |
} |
This file contains 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 toPartition = (partitioner) => (result, el) => { | |
if (partitioner(el)) | |
result[0].push(el) | |
else | |
result[1].push(el) | |
return result | |
} | |
const partition = (list, partitioner) => |