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

Skip to content

Commit 5c8fcc4

Browse files
committed
adding script wesbos#17
1 parent 2a8a7ae commit 5c8fcc4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

17 - Sort Without Articles/index-START.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,21 @@
4444
<ul id="bands"></ul>
4545

4646
<script>
47-
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 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+
}
4952

53+
const sortedBands = bands.sort((a,b) => strip(a) > string(b) ? 1 : -1);
54+
55+
document.querySelector('#bands').innerHTML =
56+
sortedBands
57+
.map(band => `<li>${band}</li>`)
58+
.join('');
59+
60+
61+
console.log(sortedBands);
5062
</script>
5163

5264
</body>

0 commit comments

Comments
 (0)