UNPKG

@gleefullychill/lotide

Version:

A library based off of lodash for a student project

31 lines (30 loc) 751 B
const countOnly = function(allItems, itemsToCount) { const results = []; for (const item of allItems) { if (itemsToCount[item]) { if (results[item]) { results[item] = results[item] + 1; } else { results[item] = 1; } } } return results; }; // const firstNames = [ // "Karl", // "salima", // "Agouhanna", // "Fang", // "Kavith", // "Jason", // "Salima", // "Fang", // "Joe" // ]; module.exports = countOnly; // const result1 = countOnly(firstNames, {"Jason": true, "Karima": true, "Fang": true, "Agouhanna": false}); // assertEqual(result1["Jason"], 1); // assertEqual(result1["Karima"], undefined); // assertEqual(result1["Fang"], 2); // assertEqual(result1["Agouhanna"], undefined);