Skip to content

Instantly share code, notes, and snippets.

@lvngd
Created Apr 16, 2021
Embed
What would you like to do?
let yearAlbum = {};
let yearCount = new Map();
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[i].bandAlbums.length; j++) {
if (!yearCount.has(data[i].bandAlbums[j].albumYear)) {
yearCount.set(`${data[i].bandAlbums[j].albumYear}`, 1)
} else {
yearCount.set(`${data[i].bandAlbums[j].albumYear}`, yearCount.get(`${data[i].bandAlbums[j].albumYear}`) + 1)
}
if (!(data[i].bandAlbums[j].albumYear in yearAlbum)) {
let newAlbum = [];
newAlbum.push(`${data[i].bandAlbums[j].albumName}`)
yearAlbum[`${data[i].bandAlbums[j].albumYear}`] = newAlbum;
}else{
let albumArray = yearAlbum[`${data[i].bandAlbums[j].albumYear}`];
albumArray.push(`${data[i].bandAlbums[j].albumName}`)
yearAlbum[`${data[i].bandAlbums[j].albumYear}`] = albumArray;
}
}
}
yearCount.delete('0000')
// console.log(yearCount)
console.log(yearAlbum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment