Skip to content

Instantly share code, notes, and snippets.

@YounglanHong
Last active June 12, 2020 06:25
Show Gist options
  • Save YounglanHong/594eeef968fb60cdabb3fad1f94ee550 to your computer and use it in GitHub Desktop.
Save YounglanHong/594eeef968fb60cdabb3fad1f94ee550 to your computer and use it in GitHub Desktop.
// A, An, The로 시작하는 경우, 해당단어들을 공백으로 대체
function strip(bandName) {
return bandName.replace(/^(a |the |an )/i, "").trim();
}
// sort 함수 내부에서 strip 함수로 인자를 감싸주면, 실제 데이터는 변화하지 않으면서 조건에 따라 정렬 가능
const sortedBands = bands.sort((a, b) => (strip(a) > strip(b) ? 1 : -1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment