Skip to content

Commit 96a0ddf

Browse files
committed
Sort list without 'a' and 'an' and 'the'
1 parent dfa672a commit 96a0ddf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

17 - Sort Without Articles/index-START.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
<script>
4747
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'];
4848

49+
function strip(bandName){
50+
return bandName.replace(/^(a |the |an )/i, '').trim();
51+
}
52+
53+
const sorted_bands = bands.sort((a,b) => strip(a) > strip(b) ? 1 : -1);
54+
55+
document.querySelector('#bands').innerHTML =
56+
sorted_bands.map(band => `<li>${band}</li>`).join('');
4957

5058
</script>
5159

0 commit comments

Comments
 (0)