Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

exercise done#4207

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ekbalam11 wants to merge1 commit intoironhack-labs:master
base:master
Choose a base branch
Loading
fromekbalam11:master
Open
Changes fromall 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
88 changes: 80 additions & 8 deletionssrc/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
// Iteration #1: Find the maximum
function maxOfTwoNumbers() {}
function maxOfTwoNumbers(a,b) {
if(a > b) {
return a;
} else if(a < b) {
return b
} else {
return a,b
}
}



// Iteration #2: Find longest word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];

function findLongestWord() {}
function findLongestWord(arr) {
if(arr.length === 0) {
return null
}

let longestWord = arr[0]

for (let i = 1; i < arr.length; i++) {
if(arr[i].length > longestWord.length) {
longestWord = arr[i]
}
}

return longestWord
}


// Iteration #3: Calculate the sum
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

function sumNumbers() {}
function sumNumbers(arr) {
if(arr.length === 0) {
return 0
}

const sum = arr.reduce((accumulator, arr) => accumulator + arr, 0)
console.log(sum)
return sum
}



Expand All@@ -26,13 +55,32 @@ function sum() {}
// Level 1: Array of numbers
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

function averageNumbers() {}
function averageNumbers(arr) {
if(arr == 0) {
return null
}

const sum = arr.reduce((accumulator, arr) => accumulator + arr, 0)
const average = sum / arr.length
return average

}


// Level 2: Array of strings
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];

function averageWordLength() { }
function averageWordLength(arr) {
if(arr.length === 0) {
return null
}

const totalLength = arr.reduce((acc, word) => acc + word.length, 0);
console.log('total Length: ', totalLength / arr.length);
return totalLength / arr.length


}

// Bonus - Iteration #4.1
function avg() {}
Expand All@@ -52,14 +100,30 @@ const wordsUnique = [
'bring'
];

function uniquifyArray() {}
function uniquifyArray(arr) {
if(arr.length === 0) {
return null
}

return [...new Set(arr)]

}



// Iteration #6: Find elements
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];

function doesWordExist() {}
function doesWordExist(arr, word) {
if(arr.length === 0) {
return null
}
if (!arr.includes(word)) {
return false;
}

return arr.some((word, i) => arr.indexOf(word) === arr.lastIndexOf(word));
}



Expand All@@ -78,7 +142,15 @@ const wordsCount = [
'matter'
];

function howManyTimes() {}
function howManyTimes(arr, word) {
if(arr.length === 0) {
return 0
}

const count = arr.filter(i => i === word).length;
return count

}



Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp