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

Commit 058349c

Browse files
committed
commits
1 parent b252a0c commit 058349c

File tree

12 files changed

+282
-211
lines changed

12 files changed

+282
-211
lines changed

week-2/3-extra/1-radio-stations.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
* - Create an array starting at 87 and ending in 108
1313
* - Should return this array to use in other functions
1414
*/
15-
15+
1616
// `getAllFrequencies` goes here
17+
function getAllFrequencies(array){
18+
return array;
19+
}
1720

1821
/**
1922
* Next, let's write a function that gives us only the frequencies that are radio stations.
@@ -25,7 +28,9 @@
2528
* - Return only the frequencies that are radio stations.
2629
*/
2730
// `getStations` goes here
28-
31+
function getStations(){
32+
33+
}
2934

3035
/* ======= TESTS - DO NOT MODIFY ======= */
3136

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// write your code here
77

88
var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"];
9-
10-
var longNameThatStartsWithA = findLongNameThatStartsWithA(names);
9+
function findLongNameThatStartsWithA(names){
10+
return names.length > 7;
11+
}
12+
var longNameThatStartsWithA = names.find(findLongNameThatStartsWithA);
1113

1214
console.log(longNameThatStartsWithA);
1315

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]];
1515
var students = ["Islam", "Lesley", "Harun", "Rukmini"];
1616
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];
1717

18-
var pairs = pairsByIndex.map(function(indexes) {
19-
var student = students[indexes[0]];
20-
var mentor = mentors[indexes[1]];
21-
return [student, mentor];
18+
var pairs = pairsByIndex.map(function (indexes) {
19+
if (indexes == null) {
20+
process.exit(1);
21+
}
22+
var student = students[indexes[0]];
23+
var mentor = mentors[indexes[1]];
24+
return [student, mentor];
2225
});
2326

2427
console.log(pairs);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"];
66
var group = ["Austine", "Dany", "Swathi", "Daniel"];
77

8-
var groupIsOnlyStudents; // complete this statement
9-
8+
var groupIsOnlyStudents = group.every(studentsIncludeNames); // complete this statement
9+
function studentsIncludeNames(names){
10+
return students.includes(names);
11+
}
1012
if (groupIsOnlyStudents) {
1113
console.log("The group contains only students");
1214
} else {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88

99
var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"];
1010

11-
var pairsByIndex; // Complete this statement
12-
11+
var pairsByIndex = pairsByIndexRaw.filter(filteredArray); // Complete this statement
12+
function filteredArray(array){
13+
return array.
14+
}
1315
var students = ["Islam", "Lesley", "Harun", "Rukmini"];
1416
var mentors = ["Daniel", "Irina", "Mozafar", "Luke"];
1517

16-
var pairs = pairsByIndex.map(function(indexes) {
17-
var student = students[indexes[0]];
18-
var mentor = mentors[indexes[1]];
19-
return [student, mentor];
18+
var pairs = pairsByIndex.map(function (indexes) {
19+
var student = students[indexes[0]];
20+
var mentor = mentors[indexes[1]];
21+
return [student, mentor];
2022
});
2123

2224
console.log(pairs);

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,33 @@ To be safe, they need to land on the first unamed planet that has Oxygen levels
99
Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5%
1010
*/
1111

12-
function safeLevels() {
13-
12+
function safeLevels(oxygen) {
13+
14+
return oxygen.find(items => (items > "19.5%" && items < "23.5%"));
1415
}
1516

1617
/* ======= TESTS - DO NOT MODIFY ===== */
1718

18-
const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"]
19-
const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"]
19+
const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"];
20+
const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"];
2021

2122
function test(test_name, expr) {
22-
let status;
23-
if (expr) {
24-
status = "PASSED";
25-
} else {
26-
status = "FAILED";
27-
}
28-
29-
console.log(`${test_name}: ${status}`);
23+
let status;
24+
if (expr) {
25+
status = "PASSED";
26+
} else {
27+
status = "FAILED";
28+
}
29+
30+
console.log(`${test_name}: ${status}`);
3031
}
3132

3233
test(
33-
"safeLevels function works - case 2",
34-
safeLevels(oxygenLevels1) === "19.9%"
34+
"safeLevels function works - case 2",
35+
safeLevels(oxygenLevels1) === "19.9%"
3536
);
3637

3738
test(
38-
"safeLevels function works - case 2",
39-
safeLevels(oxygenLevels2) === "20.2%"
40-
);
39+
"safeLevels function works - case 2",
40+
safeLevels(oxygenLevels2) === "20.2%"
41+
);

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

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

13-
function bushChecker() {
14-
13+
function bushChecker(bush) {
14+
if (bush.filter(color => color !== "pink").length > 0) {
15+
return "Toxic! Leave bush alone!"
16+
}
17+
else{
18+
return "Bush is safe to eat from"
19+
}
20+
1521
}
1622

1723
/* ======= TESTS - DO NOT MODIFY ===== */
1824

19-
let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"]
20-
let bushBerryColours2 = ["pink", "pink", "pink", "pink"]
25+
let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"];
26+
let bushBerryColours2 = ["pink", "pink", "pink", "pink"];
2127

2228
function test(test_name, expr) {
23-
let status;
24-
if (expr) {
25-
status = "PASSED";
26-
} else {
27-
status = "FAILED";
28-
}
29-
30-
console.log(`${test_name}: ${status}`);
29+
let status;
30+
if (expr) {
31+
status = "PASSED";
32+
} else {
33+
status = "FAILED";
34+
}
35+
36+
console.log(`${test_name}: ${status}`);
3137
}
3238

33-
test("bushChecker funtion works - case 1", bushChecker(bushBerryColours1) === "Toxic! Leave bush alone!")
34-
test("bushChecker funtion works - case 1", bushChecker(bushBerryColours2) === "Bush is safe to eat from")
39+
test(
40+
"bushChecker funtion works - case 1",
41+
bushChecker(bushBerryColours1) === "Toxic! Leave bush alone!"
42+
);
43+
test(
44+
"bushChecker funtion works - case 1",
45+
bushChecker(bushBerryColours2) === "Bush is safe to eat from"
46+
);

week-3/2-mandatory/3-space-colonies.js

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,55 @@
88
NOTE: don't include any element that is not a "family".
99
*/
1010

11-
function colonisers() {
12-
11+
function colonisers(names) {
12+
return names.filter(items => items.charAt(0) === "A" && items.includes('family'));
1313
}
1414

1515
/* ======= TESTS - DO NOT MODIFY ===== */
1616

1717
const voyagers = [
18-
"Adam family",
19-
"Potter family",
20-
"Eric",
21-
"Aldous",
22-
"Button family",
23-
"Jude",
24-
"Carmichael",
25-
"Bunny",
26-
"Asimov",
27-
"Oscar family",
28-
"Avery family",
29-
"Archer family"
18+
"Adam family",
19+
"Potter family",
20+
"Eric",
21+
"Aldous",
22+
"Button family",
23+
"Jude",
24+
"Carmichael",
25+
"Bunny",
26+
"Asimov",
27+
"Oscar family",
28+
"Avery family",
29+
"Archer family",
3030
];
3131

3232
function arraysEqual(a, b) {
33-
if (a === b) return true;
34-
if (a == null || b == null) return false;
35-
if (a.length != b.length) return false;
33+
if (a === b) return true;
34+
if (a == null || b == null) return false;
35+
if (a.length != b.length) return false;
3636

37-
for (let i = 0; i < a.length; ++i) {
38-
if (a[i] !== b[i]) return false;
39-
}
37+
for (let i = 0; i < a.length; ++i) {
38+
if (a[i] !== b[i]) return false;
39+
}
4040

41-
return true;
41+
return true;
4242
}
4343

4444
function test(test_name, expr) {
45-
let status;
46-
if (expr) {
47-
status = "PASSED";
48-
} else {
49-
status = "FAILED";
50-
}
51-
52-
console.log(`${test_name}: ${status}`);
45+
let status;
46+
if (expr) {
47+
status = "PASSED";
48+
} else {
49+
status = "FAILED";
50+
}
51+
52+
console.log(`${test_name}: ${status}`);
5353
}
5454

55-
test("colonisers function works",
56-
arraysEqual(colonisers(voyagers), ["Adam family", "Avery family", "Archer family"])
57-
)
55+
test(
56+
"colonisers function works",
57+
arraysEqual(colonisers(voyagers), [
58+
"Adam family",
59+
"Avery family",
60+
"Archer family",
61+
])
62+
);

week-3/2-mandatory/4-eligible-students.js

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,57 @@
77
- Returns an array containing only the names of the who have attended AT LEAST 8 classes
88
*/
99

10-
function eligibleStudents() {
11-
10+
function eligibleStudents(array) {
11+
let newArray = array.filter(function (name) {
12+
return name[1] >= 8;
13+
});
14+
let qulifiedAttendant = newArray.map(function (names) {
15+
return names[0];
16+
});
17+
console.log(qulifiedAttendant);
18+
return qulifiedAttendant;
1219
}
1320

1421
/* ======= TESTS - DO NOT MODIFY ===== */
1522

1623
const attendances = [
17-
["Ahmed", 8],
18-
["Clement", 10],
19-
["Elamin", 6],
20-
["Adam", 7],
21-
["Tayoa", 11],
22-
["Nina", 10]
23-
]
24+
["Ahmed", 8],
25+
["Clement", 10],
26+
["Elamin", 6],
27+
["Adam", 7],
28+
["Tayoa", 11],
29+
["Nina", 10],
30+
];
2431

2532
function arraysEqual(a, b) {
26-
if (a === b) return true;
27-
if (a == null || b == null) return false;
28-
if (a.length != b.length) return false;
29-
30-
for (let i = 0; i < a.length; ++i) {
31-
if (a[i] !== b[i]) return false;
32-
}
33-
34-
return true;
33+
if (a === b) return true;
34+
if (a == null || b == null) return false;
35+
if (a.length != b.length) return false;
36+
37+
for (let i = 0; i < a.length; ++i) {
38+
if (a[i] !== b[i]) return false;
39+
}
40+
41+
return true;
3542
}
3643

3744
function test(test_name, expr) {
38-
let status;
39-
if (expr) {
40-
status = "PASSED";
41-
} else {
42-
status = "FAILED";
43-
}
44-
45-
console.log(`${test_name}: ${status}`);
45+
let status;
46+
if (expr) {
47+
status = "PASSED";
48+
} else {
49+
status = "FAILED";
50+
}
51+
52+
console.log(`${test_name}: ${status}`);
4653
}
4754

48-
test("eligibleStudents function works",
49-
arraysEqual(
50-
eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"]
51-
)
52-
)
55+
test(
56+
"eligibleStudents function works",
57+
arraysEqual(eligibleStudents(attendances), [
58+
"Ahmed",
59+
"Clement",
60+
"Tayoa",
61+
"Nina",
62+
])
63+
);

0 commit comments

Comments
 (0)