This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy path4-space-colonies.js
More file actions
53 lines (44 loc) · 1.29 KB
/
4-space-colonies.js
File metadata and controls
53 lines (44 loc) · 1.29 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
/*
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".
HINT: Whenever you read the above the instructions, try to come up with the main input
and output and logic
Input: Is an array
Output: Is an array
Logic: Only strings that start with A, and finish with family
*/
function getSettlers(family) {
return family.filter(i => {
return i.startsWith("A") && i.endsWith(" family")
})
}
/* ======= TESTS - DO NOT MODIFY ===== */
test("getSettlers function works", () => {
const voyagers = [
"Adam family",
"Potter family",
"Eric",
"Aldous",
"Button family",
"Jude",
"Carmichael",
"Bunny",
"Asimov",
"Oscar family",
"Avery family",
"Archer family",
"Just A. family",
"A Great family",
];
expect(getSettlers(voyagers)).toEqual([
"Adam family",
"Avery family",
"Archer family",
"A Great family",
]);
});