-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathday5-arrow-functions.js
More file actions
31 lines (26 loc) · 1016 Bytes
/
Copy pathday5-arrow-functions.js
File metadata and controls
31 lines (26 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
Objective
In this challenge, we practice using arrow functions. Check the attached tutorial for more details.
Task
Complete the function in the editor. It has one parameter: an array, nums. It must iterate through the array performing one of the following actions on each element:
- If the element is even, multiply the element by 2.
- If the element is odd, multiply the element by 3.
- The function must then return the modified array.
Input Format
- The first line contains an integer, n, denoting the size of nums.
- The second line contains n space-separated integers describing the respective elements of nums.
Constraints
- 1 <= n <= 10
- 1 <= nums[i] <= 100, where nums[i] is the i'th element of nums.
Output Format
Return the modified array where every even element is doubled and every odd element is tripled.
*/
function modifyArray(nums) {
return nums.map((curr) => {
if (curr % 2 == 0) {
return curr * 2;
} else {
return curr * 3;
}
});
}