Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7158ff7

Browse files
committed
17th exercise done
1 parent b9a23a8 commit 7158ff7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

17 - Sort Without Articles/index-START.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,24 @@
4343
<ul id="bands"></ul>
4444

4545
<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'];
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+
const bandList = document.getElementById('bands');
4748

49+
function strip(bandName) {
50+
return bandName.toLowerCase().replace(/^(a |an |the )/i, '').trim();
51+
}
4852

53+
const sorted = bands.sort((a, b) => {
54+
if (strip(a) > strip(b)) {
55+
return 1;
56+
}
57+
if (strip(a) < strip(b)) {
58+
return -1;
59+
}
60+
return 0;
61+
});
62+
63+
bandList.innerHTML = sorted.map(bandName => `<li>${bandName}</li>`).join('');
4964
</script>
5065

5166
</body>

0 commit comments

Comments
 (0)