-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (73 loc) · 1.76 KB
/
Copy pathscript.js
File metadata and controls
84 lines (73 loc) · 1.76 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var even = [];
var odd = [];
var invalid = [];
function evenOrOdd(arr) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] < 0) {
invalid.push(arr[i]);
} else if (arr[i] === 0) {
invalid.push(arr[i]);
} else if (arr[i] % 2 === 0) {
even.push(arr[i]);
} else {
odd.push(arr[i]);
}
}
return {
evenarray : even,
oddarray : odd,
invalidarray: invalid
}
}
console.log(evenOrOdd([1, 2, 3, 4, 5, 0, -5, 6, 7, 8]));
/*
home work:
1. print the numbers from 1 to 100 with the interval of 10
var result =[]
function odd (arr)
{
for (var i=0; i<arr.length; i++){
if (arr[i] % 2 !== 0){
result.push(arr[i])
}
}
return result
}
console.log(odd([1,2,3,4,5,6,7,8,9,10]));
2. print the number from 10 to 1
var result =[]
var add = function (arr)
{
for (var i=0; i<arr.length; i++){
if (arr[i] % 2 !== 0){
result.push(arr[i])
}
}
return result
}
console.log(odd([1,2,3,4,5,6,7,8,9,10]));
3. print the multiple of 2 until 10
var result =[];
(function (arr)
{
for (let i=0; i<arr.length; i++){
if (arr[i] % 2 !== 0){
result.push(arr[i])
}
}
console.log(result);
}) ([1,2,3,4,5,6,7,8,9,10]);
4. print the number from 100 to 1 with the difference of 10.
var result = []
const odd = (arr) => {
for(let i=0;i<arr.length;i++){
if(arr[i]%2!==0){
result.push(arr[i])
}
}
return result
}
console.log(odd([1,2,3,4,5,6,7,8,9,10]));
5.write a function to print the eligble, Not eligble voters separately from the list
of array [18,17,16,15,10,8,7,9,35,40,86,75,0]. Note: print invalid if the voter age is 0.
*/