2020-02-02
정리
: Javascript30을 공부한 내용 기록
배열의 정렬 조건을 만든 후 원본의 값을 정렬하여 보여준다.
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 ul = document.querySelector('#bands');
const removeArticle = (value) => value.replace(/^(a |the |an )/i, '').trim();
const sortedBands = bands.sort((a, b) =>
removeArticle(a) > removeArticle(b) ? 1 : -1
);
ul.innerHTML = sortedBands.map((band) => `<li>${band}</li>`).join('');
👋