[Javascript2] add returnArticles to reinsert articles

This commit is contained in:
Nicola Clark 2025-04-06 22:28:46 -05:00
parent 0a8355c190
commit 10a009f630
Signed by: nicola
GPG Key ID: BEF8036296D094BF

View File

@ -31,5 +31,22 @@ function removeArticles(band) {
return band;
}
const bandsWithoutArticles = bands.map(removeArticles);
console.log(bandsWithoutArticles);
/**
* Reinserts articles into a band name
* @param {string} band band name to reinsert the article
* @returns {string} the band name with the article reinserted (if applicable)
*/
function returnArticles(band) {
for (const originalBand of bands) {
if (originalBand.endsWith(band)) {
return originalBand;
}
}
// we shouldn't end up here; every band with an article removed should have a
// corresponding original band name.
return '???';
}
const sortedBands = bands.map(removeArticles).sort().map(returnArticles);
console.log(sortedBands);