Skip to content

Instantly share code, notes, and snippets.

@pjlamb12
Created August 29, 2019 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjlamb12/5559192f2266289d88b0548499ea267d to your computer and use it in GitHub Desktop.
Save pjlamb12/5559192f2266289d88b0548499ea267d to your computer and use it in GitHub Desktop.
Book/Rating List for Blake
const bookList = [['Book 1', 'some Author'], ['Book 2', 'some Author'], ['Book 3', 'some Author']];
const ratingList = [[0, 3, 5], [3, 0, 5]];
const nameList = ['Preston', 'Blake'];
function getRatings() {
let personIndex = 0;
const returnObj = {};
while (personIndex < nameList.length) {
const personName = nameList[personIndex];
const ratings = ratingList[personIndex];
let bookIndex = 0;
while (bookIndex < bookList.length) {
const book = bookList[bookIndex];
const bookName = `${book[0]}, ${book[1]}`;
const rating = ratings[bookIndex];
if (rating > 0) {
if (!returnObj[personName]) {
returnObj[personName] = {};
}
returnObj[personName][bookName] = rating;
}
bookIndex += 1;
}
personIndex += 1;
}
return returnObj;
}
const ratingsObj = getRatings();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment