These are programming paradigms:
Declarative: tells What to do
Crucial: tells The best way to do
Instance: Discover the summation of wage for the workers with dept ‘justCode’
Crucial Fashion:
const workers = [
{id: 1, name: 'james', dept: 'admin', salary: 10000},
{id: 1, name: 'Tom', dept: 'finance', salary: 10000},
{id: 1, name: 'peter', dept: 'justCode', salary: 12500},
{id: 1, name: 'tunner', dept: 'justCode', salary: 14500},
];
const justCodeDept = [];
// filter workers based mostly on dept title.
for (let i=0; i<workers.size; i++) {
if (workers[i].dept === 'justCode') {
justCodeDept.push(workers[i]);
}
}
// summation of justCodeDept workers.
let summation = 0;
for (j = 0; j<justCodeDept.size; j++) {
summation = summation + justCodeDept[j].wage;
}
console.log(summation);
Declarative Fashion:
const workers = [
{id: 1, name: 'james', dept: 'admin', salary: 10000},
{id: 1, name: 'Tom', dept: 'finance', salary: 10000},
{id: 1, name: 'peter', dept: 'justCode', salary: 12500},
{id: 1, name: 'tunner', dept: 'justCode', salary: 14500},
];
console.log(workers.filter(merchandise => merchandise.dept === 'justCode').cut back(((previousValue, currentValue) => previousValue += currentValue.wage), 0));