Skip to content

Commit b94fc9e

Browse files
committed
Sort names ignoring articles
1 parent 1a49ea2 commit b94fc9e

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "esnext": true }
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Sort Without Articles</title>
6+
</head>
7+
<body>
8+
9+
<style>
10+
body {
11+
font-family: sans-serif;
12+
background: url("https://source.unsplash.com/nDqA4d5NL0k/2000x2000");
13+
background-size: cover;
14+
display: flex;
15+
align-items: center;
16+
min-height: 100vh;
17+
}
18+
19+
#bands {
20+
list-style: inside square;
21+
font-size: 20px;
22+
background: white;
23+
width: 500px;
24+
margin: auto;
25+
padding: 0;
26+
box-shadow: 0 0 0 20px rgba(0, 0, 0, 0.05);
27+
}
28+
#bands li {
29+
border-bottom: 1px solid #efefef;
30+
padding: 20px;
31+
}
32+
#bands li:last-child {
33+
border-bottom: 0;
34+
}
35+
36+
a {
37+
color: #ffc600;
38+
text-decoration: none;
39+
}
40+
41+
</style>
42+
43+
<ul id="bands"></ul>
44+
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+
// function to strip out the article from a band name
49+
function strip(bandName) {
50+
return bandName.replace(/^(a |the |an )/i, '').trim();
51+
}
52+
53+
const sortedBands = bands.sort(function(a, b){
54+
if (strip(a) > strip(b)) {
55+
return 1;
56+
} else {
57+
return -1;
58+
}
59+
});
60+
61+
// const sorted = bands.sort((a, b) => strip(a) > strip(b) ? 1 : -1);
62+
63+
console.log(sortedBands);
64+
65+
document.querySelector('#bands').innerHTML =
66+
sortedBands
67+
.map(band => `<li>${band}</li>`)
68+
.join('');
69+
</script>
70+
71+
</body>
72+
</html>

0 commit comments

Comments
 (0)