This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy path3-space-colonies.js
More file actions
58 lines (46 loc) · 1.31 KB
/
3-space-colonies.js
File metadata and controls
58 lines (46 loc) · 1.31 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
/*
The voyagers decide that they quite like this planet, and some of them want to settle there and colonise it.
They call the planet "Alpha" and they decide that the FAMILIES whose last names start with 'A' should stay,
while the others go on in search of other planets to call home.
Create a function that returns an array of colonisers that will stay, according to the above rules.
NOTE: don't include any element that is not a "family".
*/
function colonisers(arr) {
return arr.filter(item => item.startsWith("A") && item.includes("family"));
}
/* ======= TESTS - DO NOT MODIFY ===== */
const voyagers = [
"Adam family",
"Potter family",
"Eric",
"Aldous",
"Button family",
"Jude",
"Carmichael",
"Bunny",
"Asimov",
"Oscar family",
"Avery family",
"Archer family"
];
function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}
console.log(`${test_name}: ${status}`);
}
test("colonisers function works",
arraysEqual(colonisers(voyagers), ["Adam family", "Avery family", "Archer family"])
)