Skip to content

Commit a0c83c3

Browse files
author
Justin Ramel
committed
clean up sort code
1 parent cd33b41 commit a0c83c3

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

17 - Sort Without Articles/index-START.html

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,11 @@
4444

4545
<script>
4646
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 clean = (text) => text.replace(/a |the |an /gi, '')
48+
const sortedBands = bands.sort((a,b) => clean(a) > clean(b) ? 1 : -1)
49+
const list = sortedBands.map(band => `<li>${band}</li>`).join('')
4750

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
51+
document.querySelector('#bands').innerHTML = list
6452

6553
</script>
6654

0 commit comments

Comments
 (0)