Skip to content

Commit 4c4868e

Browse files
author
Kyle Bradshaw
committed
17 sort w/o articles v1 kb
1 parent bad0082 commit 4c4868e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

17 - Sort Without Articles/index-START.html renamed to 17 - Sort Without Articles/index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,34 @@
4343
<ul id="bands"></ul>
4444

4545
<script>
46+
4647
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'];
4748

4849

50+
// 1. fix bands w/o articles?
51+
// 2. figure indexes
52+
// 3. set sort algo on indexes
53+
54+
const articles = ['The','An','A'];
55+
56+
let bandsSorted = bands.sort(function(a, b) {
57+
a = a.replace(/The\s/, '').replace(/An\s/, '').replace(/A\s/, '');
58+
b = b.replace(/The\s/, '').replace(/An\s/, '').replace(/A\s/, '');
59+
console.log(a, b, a < b, b < a);
60+
return (a > b) ? 1 : -1;
61+
});
62+
63+
console.log(bands, bandsSorted);
64+
65+
const bandsSortedHTML = bandsSorted.reduce((last, band) => {
66+
return `
67+
${last}
68+
<li>${band}</li>
69+
`
70+
},'')
71+
72+
document.getElementById('bands').innerHTML = bandsSortedHTML;
73+
4974
</script>
5075

5176
</body>

0 commit comments

Comments
 (0)