Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let sum = 0;
- for (let i = 0; i < input.length; i ++){
- Number(input[i]) % 2 === 0 ? sum += Number(input[i]) : sum;
- }
- console.log(sum);
- }
- Решение със map(), filter() и reduce():
- function solve(input) {
- let evenNum = input.map(Number).filter(a => a % 2 === 0);
- let sum = evenNum.reduce((a, b) => a + b, 0);
- console.log(sum);
- }
- Или:
- function solve(input) {
- console.log(input.map(Number).filter(a => a % 2 === 0).reduce((a, b) => a + b, 0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement