VivaTychina / PROFE-ALGORITMS.

0 stars 0 forks source link

рефакторинг проекта используя forEach #8

Open VivaTychina opened 1 year ago

VivaTychina commented 1 year ago

function getCommonElements(firstArray, secondArray) { const commonElements = []; // Change code below this line

for (let i = 0; i < firstArray.length; i += 1) { if (secondArray.includes(firstArray[i])) { commonElements.push(firstArray[i]); } }

return commonElements; // Change code above this line }

function getCommonElements(firstArray, secondArray) { const commonElements = [];

firstArray.forEach(element => {
    if (secondArray.includes(element)) {
        commonElements.push(element);
    }
});

return commonElements;

}