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

[MAD PP] Abdallah - Miko#259

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

Closed
aberouch wants to merge6 commits intoironhack-labs:masterfromaberouch:master
Closed
Show file tree
Hide file tree
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
Binary file added.DS_Store
View file
Open in desktop
Binary file not shown.
86 changes: 84 additions & 2 deletionsstarter-code/src/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
// Find the maximum

function maxOfTwoNumbers(num1, num2){
if (num1 > num2)
{
return num1;
}
else {return num2;}
}
// Finding Longest Word
var words = [
'mystery',
Expand All@@ -11,14 +18,42 @@ var words = [
'crackpot'
];

function findLongestWord(wordList) {
var longestWord = wordList[0];
for (var i = 1; i <wordList.length; i++){
if (wordList[i].length > longestWord.length){
longestWord = wordList[i];
}
}
return longestWord;
}

// Calculating a Sum

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
function sumArray(numberList){
var totalSum = 0;
numberList.forEach(function(e){
totalSum += e;
})
return totalSum;
}

// Calculate the Average

var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

function averageNumbers(numberList){


if (numberList.length > 0){
var totalSum = sumArray(numberList);
var average = totalSum / numberList.length;
return average;
}

}

// Array of Strings
var wordsArr = [
'seat',
Expand All@@ -33,6 +68,17 @@ var wordsArr = [
'palace'
];

function averageWordLength(wordList){
if (wordList.length > 0){
var totalLetters = 0;

wordList.forEach(function(e,i){
totalLetters += wordList[i].length;
})
return totalLetters / wordList.length;
}
}

// Unique Arrays
var wordsUnique = [
'crab',
Expand All@@ -44,10 +90,22 @@ var wordsUnique = [
'playground',
'poison',
'communion',
'simple',
'bring'

];

function uniquifyArray(wordList){
console.log(wordList)
var uniqueArray = [];
if (wordList.length > 0){
for ( var i = 0; i < wordList.length; i++){
if((wordList.indexOf(wordList[i],i+1)) == -1){
uniqueArray.push(wordList[i]);
}
}
console.log(uniqueArray)
return uniqueArray;
}
}
// Finding Elements
var wordsFind = [
'machine',
Expand All@@ -60,6 +118,16 @@ var wordsFind = [
'disobedience'
];

function doesWordExist(wordList, word){
for (var i = 0; i < wordList.length; i++){

if (word == wordList[i]){
return true;
}
}
return false;

}
// Counting Repetion
var wordsCount = [
'machine',
Expand All@@ -74,6 +142,20 @@ var wordsCount = [
'disobedience',
'matter'
];

function howManyTimes(wordList, word){
var counter = 0;
if (wordList.length > 0){
for (var i = 0; i < wordList.length; i++){

if (word == wordList[i]){
counter++;
}
}
return counter;
}
return false;
}
// Bonus Quest

var matrix = [
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp