-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8-sorting-algorithm.js
More file actions
70 lines (57 loc) · 1.55 KB
/
8-sorting-algorithm.js
File metadata and controls
70 lines (57 loc) · 1.55 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
59
60
61
62
63
64
65
66
67
68
69
70
/*
At the start of the course, you worked in teams to sort your team members, labelled by
numbers, in ascending or descending order.
Today, you will be applying the sorting algorithm you used in that exercise in code!
Create a function called sortAges which:
- takes an array of mixed data types as input
- removes any non-number data types without using the built-in javascript filter method
- returns an array of sorted ages in ascending order
- HARD MODE - without using the built-in javascript sort method 😎
You don't have to worry about making this algorithm work fast! The idea is to get you to
"think" like a computer and practice your knowledge of basic JavaScript.
*/
function sortAges(arr) {}
/* ======= TESTS - DO NOT MODIFY ===== */
const agesCase1 = [
"🎹",
100,
"💩",
55,
"🥵",
"🙈",
45,
"🍕",
"Sanyia",
66,
"James",
23,
"🎖",
"Ismeal",
];
const agesCase2 = ["28", 100, 60, 55, "75", "🍕", "Elamin"];
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(
"sortAges function works - case 1",
arraysEqual(sortAges(agesCase1), [23, 45, 55, 66, 100])
);
test(
"sortAges function works - case 2",
arraysEqual(sortAges(agesCase2), [55, 60, 100])
);