Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day17 #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 43 additions & 26 deletions src/components/days/individual_days/Day17.vue
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
<template>
<div>
<ul id="bands"></ul>
<ul id="bands">
<li v-for="band in sortedBands" :key="band">{{ band }}</li>
</ul>
</div>
</template>

<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",
];
// Using Regex to remove articles on bands
function articleBanishment(bandName) {
return bandName.replace(/^(a |the |an )/i, "").trim();
}
export default {
mounted() {
this.sortBands();
},
data() {
return {
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",
],
sortedBands: [],
};
},
methods: {
// Need to find a way to push data into the sortedbands array in a sorted way
sortBands() {
this.sortedBands = this.bands.sort((a, b) => {
this.articleBanishment(a) > this.articleBanishment(b) ? 1 : -1;
});
},
articleBanishment(bandName) {
// Using Regex to remove articles on bands
return bandName.replace(/^(a |the |an )/i, "").trim();
},
},
};

//Using the above function to sort the bands without changing them
const sortedBands = bands.sort((a, b) =>
articleBanishment(a) > articleBanishment(b) ? 1 : -1
);

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

<style scoped>
Expand Down