Skip to content

Commit

Permalink
Finalizando o dia 17
Browse files Browse the repository at this point in the history
  • Loading branch information
herminiotorres committed Jul 17, 2018
1 parent 5e841b2 commit d390705
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion 17-SortWithoutArticles/finish.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,26 @@
<ul id="bands"></ul>

<script>
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'];
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'];

// const sortedBands = bands.sort(function(a, b) {
// if(a > b) {
// return 1;
// } else {
// return -1;
// }
// });

const sortedBands = bands.sort((a,b) => strip(a) > strip(b) ? 1 : -1);

function strip(bandName) {
return bandName.replace(/^(a |the |an )/i, '').trim();
}

document.querySelector('#bands').innerHTML =
sortedBands
.map(band => `<li>${band}</li>`)
.join('');
</script>

</body>
Expand Down

0 comments on commit d390705

Please sign in to comment.