Skip to content

Instantly share code, notes, and snippets.

@shapkarin
Last active February 13, 2019 09:08
Show Gist options
  • Save shapkarin/32f6fba435cbb8d3f5c2 to your computer and use it in GitHub Desktop.
Save shapkarin/32f6fba435cbb8d3f5c2 to your computer and use it in GitHub Desktop.
test task redundancy remix)
var salary = employees.reduce(function (result, employee) {
return result + (employee.sex === 'female') ? employee.salary : false /*or 0*/;
}, 0);
console.log(salary);
//задача: посчитать сумму зарплат всех сотрудников женского пола
var rand = function(min, max) {
return (Math.random() * (max - min + 1) + min)^0;
},
employees = [], check = '';
for (var i = 0; i <= 10; i++){
employees.push(
{
salary: rand(50,150) * 1000,
sex: rand(0,1) ? 'female' : 'male'
}
);
}
employees.forEach(function(employe){
check += employe.sex === 'female' ? '+' + employe.salary : '';
});
console.log(check.substring(1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment