Repository navigation
Expand file tree
/
Copy path11-problems.js
More file actions
68 lines (61 loc) · 1.57 KB
/
Copy path11-problems.js
File metadata and controls
68 lines (61 loc) · 1.57 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
/*
1. Write a function that when given an array sums only the odd values
and returns that sum. Assume the array is an array of integers.
*/
const oddSum = array => {
return array.reduce((prev, curr) => (curr % 2 ? prev + curr : prev), 0);
};
// console.log(oddSum([1, 2, 3, 4, 9]));
// 2. Given the following array, create a function that when you pass it students
// array with the passing mark, it returns the names of the students who passed;
// consdider using filters and the es6 map
var students = [
{
name: "corey",
score: 89
},
{
name: "rachel",
score: 95
},
{
name: "alex",
score: 91
},
{
name: "John",
score: 76
},
{
name: "Heck",
score: 90
}
];
const passing = (array, grade) => {
const passingStudent = [];
array.filter(a => {
if (a.score >= grade) {
return passingStudent.push(a.name);
}
});
return passingStudent;
};
// example of returning a boolean
const isBigEnough = value => value >= 10;
// console.log(isBigEnough(15));
const passing_again = (array, grade) => {
return array.filter(a => a.score >= grade).map(a => a.name);
};
// both methods should be able to work
// console.log(passing(students, 90));
console.log(passing_again(students, 90));
/*
3. Write a JavaScript for loop that will iterate from 0 to 15. For each iteration, it will check if the current number is odd or even, and display a message to the screen.
Sample Output:
"0 is even"
"1 is odd"
"2 is even"
*/
for (let x = 0; x <= 15; x++) {
x % 2 === 0 ? console.log(`${x} is even`) : console.log(`${x} is odd`);
}