I want to change the ing array using map method into newIng where I changed the units.
const unitsLong = ['tablespoons', 'tablespoon', 'ounces', 'ounce', 'teaspoons', 'teaspoon', 'cups', 'pounds'];
const unitsShort = ['tbsp', 'tbsp', 'oz', 'oz', 'tsp', 'tsp', 'cup', 'pound'];
let ing = [
"8 ounces cream cheese, softened",
"1/4 teaspoon garlic powder",
" teaspoon dried oregano",
" teaspoon dried parsley",
" teaspoon dried basil",
"1 cups shredded mozzarella cheese",
"1 cups parmesan cheese",
"1 cups pizza sauce",
"1/4 cups chopped green bell pepper",
"1/4 cups chopped onion",
"2 ounces sliced pepperoni"
];
const newIng = ing.map(el => {
unitsLong.forEach((unit, i) => {
el = el.replace(unit, unitsShort[i]);
});
});
console.log(newIng);
My expected result would be the same array where the units are shortened. Thanks!
.mapcallback isn't returning anythingmapreturn el;