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

Commit 6d45131

Browse files
committed
week-3-JavaScript-HomeWork(All++++)
1 parent 6bd6418 commit 6d45131

File tree

20 files changed

+176
-26
lines changed

20 files changed

+176
-26
lines changed

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
function findLongNameThatStartsWithA(names){
89
let output=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-
var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
109

10+
var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
11+
let test=pairsByIndex.some(function(value){
12+
return value===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
var students = ["Islam", "Lesley", "Harun", "Rukmini"];
1625
var mentors = ["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
var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"];
66
var group = ["Austine", "Dany", "Swathi", "Daniel"];
77

8-
var groupIsOnlyStudents; // complete this statement
8+
var groupIsOnlyStudents=group.every(function(name){
9+
return students.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
var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"];
1011

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

1316
var students = ["Islam", "Lesley", "Harun", "Rukmini"];
1417
var mentors = ["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
var numbers = [0.1, 0.2, 0.3, 0.4, 0.5];
5-
5+
var brandNewArray;
6+
brandNewArray=numbers.map(function(num){
7+
return num*100;
8+
})
9+
brandNewArray=numbers.map(num=>{
10+
return num*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
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
11-
11+
var output=arr.forEach(function(num,index){
12+
if(num%3===0 && num%5===0){
13+
console.log("FizzBuzz");
14+
}
15+
else if(num%5===0){
16+
console.log("Buzz");
17+
}
18+
else if(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
var numbers = [3, 2, 1];
7-
var sortedNumbers; // complete this statement
7+
var sortedNumbers=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
var mentors = ["Daniel", "Irina", "Rares"];
88
var students = ["Rukmini", "Abdul", "Austine", "Swathi"];
99

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

1212
/*
1313
DO NOT EDIT BELOW THIS LINE

week-3/1-exercises/H-array-methods-2/exercise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var everyone = [
1515
"Swathi"
1616
];
1717

18-
var firstFive; // complete this statement
19-
var lastFive; // complete this statement
18+
var firstFive=everyone.slice(0,5); // complete this statement
19+
var lastFive=everyone.slice(-5); // complete this statement
2020

2121
/*
2222
DO NOT EDIT BELOW THIS LINE

week-3/1-exercises/H-array-methods-2/exercise2.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
For example, capitailise("hello") should return "Hello"
77
Tip: use the string method .split() and the array method .join()
88
*/
9+
//return name.split("")[0].toUpperCase() + name.slice(1);
10+
function capitalise(str) {
11+
return str.split("")[0].toUpperCase().concat(str.slice(1));
912

10-
function capitalise(str) {}
13+
}
1114

1215
/*
1316
DO NOT EDIT BELOW THIS LINE

0 commit comments

Comments
 (0)