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] Rakeem Thomas Functions-And-Arrays #248

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 2 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
121 changes: 85 additions & 36 deletions 121 starter-code/src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
// Find the maximum
function maxOfTwoNumbers(num1, num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
}

// Finding Longest Word
var words = [
'mystery',
'brother',
'aviator',
'crocodile',
'pearl',
'orchard',
'crackpot'
];

var words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
function findLongestWord(arrayOfWords) {
let longestWord = '';
words.forEach(element => {
if (element.length > longestWord.length) {
longestWord = element;
}
});
return longestWord;
}
findLongestWord(words);
// Calculating a Sum

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
function sumArray(arrayOfNums) {
let sum = 0;
for (let i = 0; i < arrayOfNums.length; i++) {
sum += arrayOfNums[i];
}
return sum;
}

// Calculate the Average

var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
function averageNumbers(arrayOfNums) {
let sum = 0;
for (let i = 0; i < arrayOfNums.length; i++) {
sum += arrayOfNums[i];
}
return sum / arrayOfNums.length;
}

// Array of Strings
var wordsArr = [
'seat',
'correspond',
'linen',
'motif',
'hole',
'smell',
'smart',
'chaos',
'fuel',
'palace'
];
var wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
function averageWordLength(arrayOfWords) {
let sum = 0;
for (let i = 0; i < arrayOfWords.length; i++) {
sum += arrayOfWords[i].length;
}
return sum / arrayOfWords.length;
}

// Unique Arrays
var wordsUnique = [
Expand All @@ -45,21 +63,29 @@ var wordsUnique = [
'poison',
'communion',
'simple',
'bring'
'bring',
];

function uniquifyArray(arrayOfWords) {
const result = [];
arrayOfWords.map(element => {
if (result.indexOf(element) === -1) {
result.push(element);
}
});
return result;
}
// Finding Elements
var wordsFind = [
'machine',
'subset',
'trouble',
'starting',
'matter',
'eating',
'truth',
'disobedience'
];

var wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
function doesWordExist(arrayOfWords, wordToSearch) {
let doesExist = false;
for (let i = 0; i < arrayOfWords.length; i++) {
if (wordToSearch === arrayOfWords[i]) {
doesExist = true;
}
}
return doesExist;
}
// Counting Repetion
var wordsCount = [
'machine',
Expand All @@ -72,8 +98,18 @@ var wordsCount = [
'matter',
'truth',
'disobedience',
'matter'
'matter',
];

function howManyTimes(arrayOfWords, wordToSearch) {
let count = 0;
for (let i = 0; i < arrayOfWords.length; i++) {
if (wordToSearch === arrayOfWords[i]) {
count += 1;
}
}
return count;
}
// Bonus Quest

var matrix = [
Expand All @@ -96,5 +132,18 @@ var matrix = [
[4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36],
[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16],
[20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54],
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48],
];

function greatestProduct(matrixArray) {
var product = 0;
var tempProduct;
// every four numbers, test product
for (var i = 0; i < matrixArray.length; i++) {
for (var j = 0; j < matrixArray[i].length; j++) {
console.log(matrixArray[i][j]);
}
}
}

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