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

MIA-Ariel-Fonticiella & Imran #161

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
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
75 changes: 65 additions & 10 deletions 75 starter-code/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
// Find the maximum
function maxOfTwoNumbers (first, second) {

if (first > second) {
return first;
} else if (first < second) {
return second;
} else {
return first;
}
}

var largest = maxOfTwoNumbers(2, 6);
console.log(largest);

// Finding Longest Word
function findLongestWord (words) {

var largest = "";
var max = 0;
words.forEach (function (element) {
if (element.length > max) {
max = element.length;
largest = element;
}
});
return largest;
}

var words = [
Expand All @@ -25,7 +38,11 @@ console.log(longest);

// Calculating a Sum
function sumArray (array) {

var sum = 0;
numbers.forEach(function (add){
sum += add;
});
return sum;
}

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
Expand All @@ -34,7 +51,11 @@ console.log(total);

// Calculate the Average
function averageNumbers (array) {

var sum = 0;
numbers.forEach(function(add){
sum += add;
});
return sum/array.length;
}

var numbers = [2, 6, 9, 10, 7, 4, 1, 9];
Expand All @@ -43,7 +64,11 @@ console.log(average);

// Array of Strings
function averageWordLength (array) {

var length = 0;
words.forEach(function(element){
length += element.length;
});
return length/array.length;
}

var words = [
Expand All @@ -63,7 +88,13 @@ console.log(averageLength);

// Unique Arrays
function uniquifyArray (array) {

var newArray = [];
words.forEach(function (element){
if (newArray.indexOf(element) === -1) {
newArray.push(element);
}
});
return newArray;
}

var words = [
Expand All @@ -84,7 +115,13 @@ console.log(uniqued);

// Finding Elements
function doesWordExist (wordsArray, word) {

var exist = false;
wordsArray.forEach(function (element){
if (element === word) {
exist = true;
}
});
return exist
}

var words = [
Expand All @@ -106,7 +143,13 @@ console.log(hasDog);

// Counting Repetion
function howManyTimes (words, word) {

var repeat = 0;
for(var i = 0; i < words.length; i++) {
if (words[i] === word) {
repeat++;
}
}
return repeat;
}

var words = [
Expand All @@ -131,7 +174,19 @@ console.log(howManyDog);

// Bonus Quest
function greatestProduct (matrix) {
var product = 0;
for (var i = 0; i < matrix.length -1; i++){
for (var j = 0; j < matrix[i].length -1; j++){


// console.log("i is", i);
// console.log("j is", j);
// console.log(matrix[i][j]);


product = matrix[i][j] * matrix[i][j+1] * matrix[i][j-1];
}
}
}

var matrix = [
Expand All @@ -158,4 +213,4 @@ var matrix = [
];

var maxProduct = greatestProduct(matrix);
console.log(maxProduct);
// console.log(maxProduct);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.