Skip to content

[FTRMT052023] Marco #3797

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
done
  • Loading branch information
mk3346 committed May 11, 2023
commit bcf0996f7563ce596e7907cfe30d0be508a6b90c
50 changes: 45 additions & 5 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ function maxOfTwoNumbers(num1, num2) {
return Math.max(num1, num2);
}

const maximum = maxOfTwoNumbers(10, 20);
console.log(maximum);


// Iteration #2: Find longest word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
Expand Down Expand Up @@ -137,8 +134,16 @@ const wordsCount = [
'matter'
];

function howManyTimes() {}
function howManyTimes(inputArray, countWord) {

let sum = 0;
for (let i = 0; i < inputArray.length; i++) {
if (inputArray[i] === countWord) {
sum += 1;
}
}
return sum;
}


// Iteration #8: Bonus
Expand All @@ -165,7 +170,42 @@ const matrix = [
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]
];

function greatestProduct() {}
function greatestProduct(bigArray) {
let maxProduct = 0;

// Find the greatest product of four adjacent numbers horizontally
for (let i = 0; i < bigArray.length; i++) {
for (let j = 0; j < bigArray[i].length - 3; j++) {
let product =
bigArray[i][j] *
bigArray[i][j + 1] *
bigArray[i][j + 2] *
bigArray[i][j + 3];
if (product > maxProduct) {
maxProduct = product;
}
}
}

// Find the greatest product of four adjacent numbers vertically
for (let i = 0; i < bigArray.length - 3; i++) {
for (let j = 0; j < bigArray[i].length; j++) {
let product =
bigArray[i][j] *
bigArray[i + 1][j] *
bigArray[i + 2][j] *
bigArray[i + 3][j];
if (product > maxProduct) {
maxProduct = product;
}
}
}

return maxProduct;
}

const result = greatestProduct(matrix);
console.log(result);



Expand Down