Skip to content

Commit 0657e1b

Browse files
committed
Finished wesbos#17
1 parent 8c148dd commit 0657e1b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

17 - Sort Without Articles/index-START.html

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Sort Without Articles</title>
67
</head>
8+
79
<body>
810

911
<style>
@@ -25,10 +27,12 @@
2527
padding: 0;
2628
box-shadow: 0 0 0 20px rgba(0, 0, 0, 0.05);
2729
}
30+
2831
#bands li {
2932
border-bottom: 1px solid #efefef;
3033
padding: 20px;
3134
}
35+
3236
#bands li:last-child {
3337
border-bottom: 0;
3438
}
@@ -37,16 +41,30 @@
3741
color: #ffc600;
3842
text-decoration: none;
3943
}
40-
4144
</style>
4245

4346
<ul id="bands"></ul>
4447

45-
<script>
46-
const bands = ['The Plot in You', 'The Devil Wears Prada', 'Pierce the Veil', 'Norma Jean', 'The Bled', 'Say Anything', 'The Midway State', 'We Came as Romans', 'Counterparts', 'Oh, Sleeper', 'A Skylit Drive', 'Anywhere But Here', 'An Old Dog'];
47-
48+
<script>
49+
const bands = ['The Plot in You', 'The Devil Wears Prada', 'Pierce the Veil', 'Norma Jean', 'The Bled', 'Say Anything', 'The Midway State', 'We Came as Romans', 'Counterparts', 'Oh, Sleeper', 'A Skylit Drive', 'Anywhere But Here', 'An Old Dog'];
50+
function removeArticle(word) {
51+
const splitWord = word.split(' ');
52+
const firstWord = splitWord[0];
53+
if (firstWord === 'The' || firstWord === 'A' || firstWord === 'An') {
54+
return splitWord.slice(1).join(' ');
55+
}
56+
return splitWord.join(' ');
57+
}
58+
const sortedBands = bands.sort((a, b) => removeArticle(a) < removeArticle(b) ? -1 : 1);
4859

49-
</script>
60+
console.log(sortedBands);
61+
let bandText = sortedBands.map(band => {
62+
return `<li>${band}</li>`
63+
}).join('');
64+
const bandEl = document.getElementById('bands');
65+
bandEl.innerHTML = bandText;
66+
</script>
5067

5168
</body>
52-
</html>
69+
70+
</html>

0 commit comments

Comments
 (0)