Skip to content

Instantly share code, notes, and snippets.

@nicobytes
Created December 2, 2020 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicobytes/9b15a67a3cbfce09bc2b1766faafacbc to your computer and use it in GitHub Desktop.
Save nicobytes/9b15a67a3cbfce09bc2b1766faafacbc to your computer and use it in GitHub Desktop.
const data = [1,3,4,5];
const rta = data.reduce((counter, item) => counter + item, 0);
console.log(rta);
const orders = [
{
customerName: 'Nicolas',
total: 60,
delivered: true,
},
{
customerName: 'Zulema',
total: 120,
delivered: false,
},
{
customerName: 'Santiago',
total: 180,
delivered: true,
},
{
customerName: 'Valentina',
total: 240,
delivered: true,
},
];
const rta = data
.map(item => item.total)
.reduce((counter, item) => counter + item, 0);
console.log(rta);
const data = [
{
name: 'Nicolas',
level: 'low'
},
{
name: 'Andrea',
level: 'medium'
},
{
name: 'Zulema',
level: 'hight'
},
{
name: 'Santiago',
level: 'low'
},
{
name: 'Valentina',
level: 'medium'
},
{
name: 'Lucia',
level: 'hight'
}
]
const rta = exams
.map(item => item.level)
.reduce((rta, item) => {
if(rta[item]) {
rta[item] = rta[item] + 1;
} else {
rta[item] = 1;
}
return rta;
}, {})
const matriz = [
[1,2,3],
[4,5,6],
[7,8,9]
];
const rta = matriz.reduce((rta, item)=> {
return [...rta, ...item];
}, []);
const rta1 = matriz.flat();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment