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

Appearance settings

[MAD PP] Gonzalo & Dennis #521

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

Closed
wants to merge 7 commits into from
Closed
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
90 changes: 90 additions & 0 deletions 90 starter-code/src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Find the maximum

function maxOfTwoNumbers (a, b) {
if (a > b) {
return a;
} else {
return b;
}
}



// Finding Longest Word
var words = [
'mystery',
Expand All @@ -11,14 +21,42 @@ var words = [
'crackpot'
];

function findLongestWord (arrayWords) {
var longestWord = "";
if (arrayWords.length == 0) {
return undefined;
}
arrayWords.forEach(function(element) {
if (element.length > longestWord.length) {
longestWord = element;
}
});
return longestWord;
}

// Calculating a Sum

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

function sumArray (arrayNums) {
var total = 0;
arrayNums.forEach(function(num) {
total += num;
});
return total;
}

// Calculate the Average

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

function averageNumbers (arrayAvg) {
if (arrayAvg.length == 0) {
return undefined;
}
return sumArray(arrayAvg) / arrayAvg.length;
}

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

function averageWordLength (arrayAvgWords) {
var arrayLengths = [];
if (arrayAvgWords.length == 0) {
return undefined;
}
arrayAvgWords.forEach(function(letters) {
arrayLengths.push(letters.length);
});
return averageNumbers (arrayLengths);
}

// Unique Arrays
var wordsUnique = [
'crab',
Expand All @@ -48,6 +97,19 @@ var wordsUnique = [
'bring'
];

function uniquifyArray (arrayNoUnique) {
var arrayUnique = [];
if (arrayNoUnique == 0) {
return undefined;
}
arrayNoUnique.forEach(function(word){
if (arrayUnique.indexOf(word) < 0) {
arrayUnique.push(word)
}
});
return arrayUnique;
}

// Finding Elements
var wordsFind = [
'machine',
Expand All @@ -60,6 +122,20 @@ var wordsFind = [
'disobedience'
];

function doesWordExist (arrayWordsSearch, wordSearched) {
var finded = false;
arrayWordsSearch.forEach(function(word) {
if (word === wordSearched) {
if (finded == false){
finded = true;
}else {
return false;
}
}
});
return finded;
}

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

function howManyTimes (arrayWordsRepeated, wordSearched) {
var count = 0;
if (arrayWordsRepeated.length == 0) {
return false;
}
arrayWordsRepeated.forEach(function(word) {
if (word === wordSearched) {
count++;
}
});
return count;
}

// Bonus Quest

var matrix = [
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.