-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoonWalker.js
More file actions
37 lines (30 loc) · 742 Bytes
/
Copy pathmoonWalker.js
File metadata and controls
37 lines (30 loc) · 742 Bytes
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
<script>
var moonWalkers = [
"Neil Armstrong",
"Buzz Aldrin",
"Pete Conrad",
"Alan Bean",
"Alan Shepard",
"Edgar Mitchell",
"David Scott",
"James Irwin",
"John Young",
"Charles Duke",
"Eugene Cernan",
"Harrison Schmitt"
];
function alphabetizer(names) {
// Your code goes here!
for(i = 0 ; i < names.length ; i++ ){
astronat = names[i];
name = astronat.slice(0,astronat.search(" "));
surname = astronat.slice(astronat.search(" ") + 1 , astronat.length);
names[i] = surname + ", " + name;
console.log(names[i]);
};
names.sort();
return names;
};
// Try logging your results to test your code!
console.log(alphabetizer(moonWalkers));
</script>