-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArrowFunctionsHR.js
70 lines (49 loc) · 1.57 KB
/
ArrowFunctionsHR.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Task
Complete the function in the editor. It has one parameter: an array, . It must iterate through the array performing one of the following actions on each element:
If the element is even, multiply the element by .
If the element is odd, multiply the element by .
The function must then return the modified array.
Input Format
The first line contains an integer, , denoting the size of .
The second line contains space-separated integers describing the respective elements of .
Constraints
, where is the element of .
Output Format
Return the modified array where every even element is doubled and every odd element is tripled.
Sample Input 0
5
1 2 3 4 5
Sample Output 0
3 4 9 8 15
Explanation 0
Given , we modify each element so that all even elements are multiplied by and all odd elements are multipled by . In other words, . We then return the modified array as our answer.
*/
// SOLUTION
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Modify and return the array so that all even elements are doubled and all odd elements are tripled.
*
* Parameter(s):
* nums: An array of numbers.
*/
function modifyArray(nums) {
var new_arr = nums.map(s => (s%2 == 0)? s*2 :s*3);
return new_arr
}