Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FT_RMT_262024_Badr #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions src/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,46 @@ 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;
}




// 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;
}



Expand All @@ -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<original.length; i++) {
if (!toRemove.includes(original[i])) {
result.push (original [i]);
}
}
return result;
}



Expand All @@ -56,7 +89,18 @@ const duplicateWords = [
"bring"
];

function uniquifyArray() {}
function uniquifyArray(WordsArray) {
if (WordsArray.length === 0 ) {
return null;
}
let uniqueArray = [];
WordsArray.forEach(word => {
if (!uniqueArray.includes(word)) {
uniqueArray.push(word);
}
});
return uniqueArray;
}



Expand Down