Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let originalSum = 0;
- let modifiedSum = 0;
- for (let i = 0; i < arr.length; i++) {
- originalSum += arr[i];
- }
- for (let i = 0; i < arr.length; i++) {
- arr[i] % 2 === 0 ? arr[i] += i : arr[i] -= i;
- }
- for (let i = 0; i < arr.length; i++) {
- modifiedSum += arr[i];
- }
- console.log(arr, `\n` + originalSum, `\n` + modifiedSum);
- }
- Решение с lambda:
- function solve(arr) {
- let originalSum = arr.reduce((a, b) => a + b, 0);
- for (let i = 0; i < arr.length; i++) {
- arr[i] % 2 === 0 ? arr[i] += i : arr[i] -= i;
- }
- let modifiedSum = arr.reduce((a, b) => a + b, 0);
- console.log(arr, `\n` + originalSum, `\n` + modifiedSum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement