Skip to content

Commit cd33b41

Browse files
author
Justin Ramel
committed
sorting using a regex
1 parent fd55651 commit cd33b41

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

17 - Sort Without Articles/index-START.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +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'];
4747

48+
const bandsDom = document.querySelector('#bands')
49+
50+
const sortedBands = bands.sort((a,b) => {
51+
const cleanA = a.replace(/a |the |an /gi, '')
52+
const cleanB = b.replace(/a |the |an /gi, '')
53+
54+
return cleanA > cleanB ? 1 : -1
55+
})
56+
57+
const list = sortedBands.map(band => {
58+
return `
59+
<li>${band}</li>
60+
`
61+
}).join('')
62+
63+
bandsDom.innerHTML = list
4864

4965
</script>
5066

0 commit comments

Comments
 (0)