aka Fizzbuzz alternatives.
getColumnsForCategories(categories) {
let categoriesCount = 0;
for (var key in categories) {
categoriesCount++;
}
let half = Math.floor(categoriesCount / 2);
let remainder = categoriesCount % half;
let categoriesLeftColumnLength = half + remainder;
let categoriesRightColumnLength = half;
let categoriesLeftColumn = new Set();
for (let i = 0; i < categoriesLeftColumnLength; i++) {
categoriesLeftColumn.add(categories[i]);
}
let categoriesRighttColumn = new Set();
for (let i = categoriesLeftColumnLength; i < (categoriesLeftColumnLength + categoriesRightColumnLength); i++) {
categoriesRighttColumn.add(categories[i]);
}
let categoriesColumns = new Map();
categoriesColumns.set('left', categoriesLeftColumn);
categoriesColumns.set('right', categoriesRighttColumn);
return categoriesColumns;
}
convertArrayOfDocumentariesToMap(documentaries, amountPerRow, amountTotal) {
let cardDecks = new Map();
let counter = 0;
for (let i in documentaries) {
if (+i === amountTotal) {
break;
}
let documentary = documentaries[i];
let cardDeck = cardDecks.get(counter);
if (cardDeck === undefined || !cardDeck) {
cardDeck = new Set();
}
cardDeck.add(documentary);
cardDecks.set(counter, cardDeck);
if (+i != 0 && (+i + 1) % amountPerRow === 0) {
counter++;
}
}
return cardDecks;
}