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

Commit ac40b46

Browse files
authored
Add files via upload
1 parent 28e5f3d commit ac40b46

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
At the start of the course, you worked in teams to sort your team members, labelled by
3+
numbers, in ascending or descending order.
4+
5+
Today, you will be applying the sorting algorithm you used in that exercise in code!
6+
7+
Create a function called sortAges which:
8+
- takes an array of mixed data types as input
9+
- removes any non-number data types without using the built-in javascript filter method
10+
- returns an array of sorted ages in ascending order
11+
- HARD MODE - without using the built-in javascript sort method 😎
12+
13+
You don't have to worry about making this algorithm work fast! The idea is to get you to
14+
"think" like a computer and practice your knowledge of basic JavaScript.
15+
*/
16+
17+
18+
function sortAges(arr) {}
19+
20+
/* ======= TESTS - DO NOT MODIFY ===== */
21+
22+
const agesCase1 = [
23+
"🎹",
24+
100,
25+
"💩",
26+
55,
27+
"🥵",
28+
"🙈",
29+
45,
30+
"🍕",
31+
"Sanyia",
32+
66,
33+
"James",
34+
23,
35+
"🎖",
36+
"Ismeal",
37+
];
38+
const agesCase2 = ["28", 100, 60, 55, "75", "🍕", "Elamin"];
39+
40+
function arraysEqual(a, b) {
41+
if (a === b) return true;
42+
if (a == null || b == null) return false;
43+
if (a.length != b.length) return false;
44+
45+
for (let i = 0; i < a.length; ++i) {
46+
if (a[i] !== b[i]) return false;
47+
}
48+
49+
return true;
50+
}
51+
52+
function test(test_name, expr) {
53+
let status;
54+
if (expr) {
55+
status = "PASSED";
56+
} else {
57+
status = "FAILED";
58+
}
59+
60+
console.log(`${test_name}: ${status}`);
61+
}
62+
63+
test(
64+
"sortAges function works - case 1",
65+
arraysEqual(sortAges(agesCase1), [23, 45, 55, 66, 100])
66+
);
67+
68+
test(
69+
"sortAges function works - case 2",
70+
arraysEqual(sortAges(agesCase2), [55, 60, 100])
71+
);

0 commit comments

Comments
 (0)