UNPKG

word-vault

Version:

A lightweight JavaScript package for English word definitions and collections.

28 lines (27 loc) 814 B
import { getAllCollections } from "./getAllCollections.js"; export function getTotalCardsByDifficulty() { const allCollections = getAllCollections(); const totalCounts = { A1: 0, A2: 0, B1: 0, B2: 0, C1: 0, C2: 0, }; if (!allCollections) { return totalCounts; } for (const collection of allCollections) { if (collection?.totalCardsByDifficulty) { for (const difficulty of Object.keys(collection.totalCardsByDifficulty)) { const key = difficulty; const difficultyCount = collection.totalCardsByDifficulty?.[key]; if (difficultyCount) { totalCounts[key] += difficultyCount; } } } } return totalCounts; }