From ce8e8f37052b9ee64d9c62580b49e2ef8a10304b Mon Sep 17 00:00:00 2001 From: Badr AB Date: Tue, 26 Nov 2024 17:31:47 +0100 Subject: [PATCH] Solved lab --- src/challenges.js | 54 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/challenges.js b/src/challenges.js index 940a599..43ce3ca 100644 --- a/src/challenges.js +++ b/src/challenges.js @@ -13,13 +13,31 @@ const repeatedWords = [ "matter" ]; -function howManyTimes() {} +function howManyTimes(WordsArray,searchWord) { + let count = 0; + for (let i = 0; i < WordsArray.length; i++) { + if (WordsArray[i] ===searchWord) { + count += 1; + } + } + return count; +} // Iteration 2 | Number Sequence -function createSequence() {} +function createSequence(n) { + if (n === 0) { + return []; + } + + let sequence =[]; + for (let i =0; i <= n; i++) { + sequence.push(i); + } + return sequence; +} @@ -27,7 +45,14 @@ function createSequence() {} // Iteration 3 | Multiply for Each const numbers = [1, 2, 5, 10, 13, 50]; -function multiplyBy() {} +function multiplyBy(numbersArray, multiplier) { + let resultArray = []; + numbersArray.forEach(number => { + resultArray.push(number*multiplier); + + }); + return resultArray; +} @@ -36,7 +61,15 @@ function multiplyBy() {} const original = ["cat", "dog", "fish", "bird", "cat", "fish"]; const toRemove = ["cat", "dog"]; -function filterOut() {} +function filterOut(original, toRemove) { + let result = []; + for (let i = 0; i { + if (!uniqueArray.includes(word)) { + uniqueArray.push(word); + } + }); + return uniqueArray; +}