-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay_with_array.js
More file actions
49 lines (45 loc) · 979 Bytes
/
Copy pathplay_with_array.js
File metadata and controls
49 lines (45 loc) · 979 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function getEven(arr) {
/*
Return an array containing only even numbers as a result
Example
Input: [1,4,5,77,8,90]
Output: [4,8,90]
Write you code below
*/
arr1=[]
for(i=0;i<arr.length;i++){
if(arr[i]%2===0){
arr1.push(arr[i])
}
}
return arr1
}
function multiplyByN(arr, n) {
/*
Return an array whose elements are multiplied by n
Example
Input: [1,3,4,55], 3
Output: [3,9,13,165]
Write you code below
*/
for(i=0;i<arr.length;i++){
arr[i]=arr[i]*n
}
return arr
}
function removeNthElement(arr, n) {
/*
Return the array with the element present at index n removed
Example
Input: [1,3,4,6,7] 3
Output: [1,3,4,7]
Write you code below
*/
arr.splice(n,1)
return arr
}
module.exports = {
getEven,
multiplyByN,
removeNthElement
}