Katas

Run Settings
LanguageJavaScript
Language Version
Run Command
const recipe = { apples: 2, flour: 500, sugar: 200, eggs: 1 }; const available1 = { flour: 1200, sugar: 1200, eggs: 5, milk: 200 }; const available = { sugar: 9, eggs: 2, milk: 1 }; function cakes(recipe, available) { const checked = { ...recipe }; Object.keys(available).forEach(item => { delete checked[item]; }); // console.log(checked); if (Object.keys(checked).length) { return 0; } else { Object.keys(available).forEach(item => { if (!Object.keys(recipe).includes(item)){ delete available[item]; } }); const ingredients = []; Object.keys(recipe).forEach(ingr => { ingredients.push(Math.floor(available[ingr]/recipe[ingr])); }); // console.log(ingredients) return Math.min(...ingredients); // console.log(available); // const oneCake = Object.keys(recipe).reduce((acc, item) => recipe[item]+acc, 0); // console.log('recipeAcc: ', (Object.keys(recipe).reduce((acc, item) => recipe[item]+acc, 0))); // console.log('availAcc: ', (Object.keys(available).reduce((acc, item) => available[item]+acc, 0))); // return ((Object.keys(available).reduce((acc, item) => available[item]+acc, 0)) % oneCake); } } // console.log(cakes(recipe, available)); console.log(cakes(recipe, available1)); // console.log(oneCake); function nbDig(n, d) { return [...Array(n+1).keys()] .map(item => item**2) .join('') .match(new RegExp(`${d}`, 'g')) .length; } console.log('Dig: ', nbDig(10, 1));
Editor Settings
Theme
Key bindings
Full width
Lines