Created
August 29, 2019 19:17
-
-
Save pjlamb12/5559192f2266289d88b0548499ea267d to your computer and use it in GitHub Desktop.
Book/Rating List for Blake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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