Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Commit 808fee4

Browse files
committed
week-3-JavaScript-HomeWork(All+)
1 parent 6975033 commit 808fee4

17 files changed

Lines changed: 169 additions & 22 deletions

File tree

‎week-3/1-exercises/A-array-find/exercise.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Using .find(), we'd like to find the first name which starts with A and is longer than 7 letters.
44
*/
55

6+
67
// write your code here
78
functionfindLongNameThatStartsWithA(names){
89
letoutput=names.find(function(name){

‎week-3/1-exercises/B-array-some/exercise.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66
- Do not edit any of the existing code
77
*/
88

9-
varpairsByIndex=[[0,3],[1,2],[2,1],null,[3,0]];
109

10+
varpairsByIndex=[[0,3],[1,2],[2,1],null,[3,0]];
11+
lettest=pairsByIndex.some(function(value){
12+
returnvalue===null;
13+
})
14+
if(test){
15+
console.log("array contain null value");
16+
process.exit(1)
17+
}
18+
else{
1119
// If there is a null value in the array exit the program with the error code
1220
// https://nodejs.org/api/process.html#process_process_exit_code
1321
// process.exit(1);
1422

23+
1524
varstudents=["Islam","Lesley","Harun","Rukmini"];
1625
varmentors=["Daniel","Irina","Mozafar","Luke"];
1726

@@ -22,3 +31,4 @@ var pairs = pairsByIndex.map(function(indexes) {
2231
});
2332

2433
console.log(pairs);
34+
}

‎week-3/1-exercises/C-array-every/exercise.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
varstudents=["Omar","Austine","Dany","Swathi","Lesley","Rukmini"];
66
vargroup=["Austine","Dany","Swathi","Daniel"];
77

8-
vargroupIsOnlyStudents;// complete this statement
8+
vargroupIsOnlyStudents=group.every(function(name){
9+
returnstudents.includes(name);
10+
});// complete this statement
911

1012
if(groupIsOnlyStudents){
1113
console.log("The group contains only students");

‎week-3/1-exercises/D-array-filter/exercise.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/*
22
You are given a program that logs pairings between mentors and students
3-
It fails because the array `pairsById` can contain different values that break the program
3+
It fails because the array `pairsById` can contain different values that
4+
break the program
45
It is decided that array items which are not pairs should be filtered out
56
- Finish the statement on line 11 to produce an array with valid content
67
- Do not edit any of the existing code
78
*/
89

910
varpairsByIndexRaw=[[0,3],[1,2],[2,1],null,[1],false,"whoops"];
1011

11-
varpairsByIndex;// Complete this statement
12+
varpairsByIndex=pairsByIndexRaw.filter(function(value){
13+
returnArray.isArray(value)&&value.length>1;
14+
});// Complete this statement
1215

1316
varstudents=["Islam","Lesley","Harun","Rukmini"];
1417
varmentors=["Daniel","Irina","Mozafar","Luke"];

‎week-3/1-exercises/E-array-map/exercise.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@
22
// Write multiple solutions using different syntax (as shown in the README)
33

44
varnumbers=[0.1,0.2,0.3,0.4,0.5];
5-
5+
varbrandNewArray;
6+
brandNewArray=numbers.map(function(num){
7+
returnnum*100;
8+
})
9+
brandNewArray=numbers.map(num=>{
10+
returnnum*100;
11+
})
12+
brandNewArray=numbers.map(num=>num*100);
13+
console.log(brandNewArray);

‎week-3/1-exercises/F-array-forEach/exercise.js‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@
88
*/
99

1010
vararr=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
11-
11+
varoutput=arr.forEach(function(num,index){
12+
if(num%3===0&&num%5===0){
13+
console.log("FizzBuzz");
14+
}
15+
elseif(num%5===0){
16+
console.log("Buzz");
17+
}
18+
elseif(num%3===0){
19+
console.log("Fizz");
20+
}
21+
else{
22+
console.log(num);
23+
}
24+
})
25+
console.log(output);
1226
/* EXPECTED OUTPUT */
1327

1428
/*

‎week-3/1-exercises/G-array-methods/exercise.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
varnumbers=[3,2,1];
7-
varsortedNumbers;// complete this statement
7+
varsortedNumbers=numbers.sort();// complete this statement
88

99
/*
1010
DO NOT EDIT BELOW THIS LINE

‎week-3/1-exercises/G-array-methods/exercise2.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
varmentors=["Daniel","Irina","Rares"];
88
varstudents=["Rukmini","Abdul","Austine","Swathi"];
99

10-
vareveryone;// complete this statement
10+
vareveryone=mentors.concat(students);// complete this statement
1111

1212
/*
1313
DO NOT EDIT BELOW THIS LINE

‎week-3/2-mandatory/1-oxygen-levels.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ To be safe to land on, a planet needs to have an Oxygen level between 19.5% and
99
Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5%
1010
*/
1111

12-
functionsafeLevels(){
13-
12+
functionsafeLevels(arr){
13+
varfindLevel=arr.find(function(level){
14+
returnparseFloat(level)>19.5&&parseFloat(level)<23.5;
15+
})
16+
returnfindLevel;
1417
}
1518

1619
/* ======= TESTS - DO NOT MODIFY ===== */

‎week-3/2-mandatory/2-bush-berries.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
Use the tests to confirm which message to return
1111
*/
1212

13-
functionbushChecker(){
14-
13+
functionbushChecker(arr){
14+
if(arr.every(function(barries){
15+
returnbarries==="pink";
16+
})){
17+
return"Bush is safe to eat from";
18+
}
19+
else{
20+
return"Toxic! Leave bush alone!";
21+
22+
}
1523
}
1624

1725
/* ======= TESTS - DO NOT MODIFY ===== */

0 commit comments

Comments
 (0)