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] ABEL ALONSO & MINYU LI#428

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
Minyu5 wants to merge1 commit intoironhack-labs:masterfromMinyu5: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.
Binary file addedstarter-code/.DS_Store
View file
Open in desktop
Binary file not shown.
Binary file addedstarter-code/jasmine/.DS_Store
View file
Open in desktop
Binary file not shown.
View file
Open in desktop
Binary file not shown.
Binary file addedstarter-code/src/.DS_Store
View file
Open in desktop
Binary file not shown.
105 changes: 102 additions & 3 deletionsstarter-code/src/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
// Find the maximum
function maxOfTwoNumbers(var1, var2) {
if (var1 >= var2) {
return var1;
}
return var2;
}

// Finding Longest Word
var words = [
Expand All@@ -10,15 +16,42 @@ var words = [
'orchard',
'crackpot'
];
function findLongestWord(arr) {
if (arr.length === 0) {
return;
}
var answer = "";
arr.forEach(function (word) {
if (word.length > answer.length) {
answer = word;
}
})
return answer;
}
console.log(findLongestWord(words));

// Calculating a Sum

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
function sumArray(arr) {
var total = 0;
arr.forEach(function (element) {
total += element;
})
return total;
}
console.log(sumArray(numbers));

// Calculate the Average

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

function averageNumbers(arr) {
if (arr.length === 0) {
return;
}
return sumArray(arr) / arr.length;
}
console.log(averageNumbers(numbersAvg));

// Array of Strings
var wordsArr = [
'seat',
Expand All@@ -32,6 +65,21 @@ var wordsArr = [
'fuel',
'palace'
];
function sumOfLettersifnotempty(arr) {
var sumof = 0;
arr.forEach(function (word) {
sumof += word.length;
}
)
return sumof;
}
function averageWordLength(arr) {
if (arr.length === 0) {
return;
}
return sumOfLettersifnotempty(arr)/arr.length;
}
console.log(averageWordLength(wordsArr));

// Unique Arrays
var wordsUnique = [
Expand All@@ -47,6 +95,19 @@ var wordsUnique = [
'simple',
'bring'
];
function uniquifyArray(arr){
if (arr.length === 0){
return undefined;
}
var newarr = [];
for (var i=0; i<arr.length;i++){
if (newarr.indexOf(arr[i])===-1){
newarr.push(arr[i]);
}
}
return newarr;
}
console.log(uniquifyArray(wordsUnique));

// Finding Elements
var wordsFind = [
Expand All@@ -59,6 +120,10 @@ var wordsFind = [
'truth',
'disobedience'
];
function doesWordExist(arr,word){
return arr.includes(word);
}
console.log(doesWordExist(wordsFind,'truth'));

// Counting Repetion
var wordsCount = [
Expand All@@ -74,8 +139,21 @@ var wordsCount = [
'disobedience',
'matter'
];
// Bonus Quest
function howManyTimes(arr,word){
if (arr.length === 0){
return false;
}
var result=0;
arr.forEach(function(element){
if (element==word){
result+=1;
}
})
return result;
}
console.log(howManyTimes(wordsCount,'machine'));

// Bonus Quest
var matrix = [
[8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8],
[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0],
Expand All@@ -98,3 +176,24 @@ var matrix = [
[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]
];
function greatestProduct(matrix){
var max=0;
var producto;
for (var r=0;r<20;r++){
for(var c=0;c<20;c++){
if (c<17){
producto=matrix[r][c]*matrix[r][c+1]*matrix[r][c+2]*matrix[r][c+3];
if (producto>max){
max=producto;
}
}
if (r<17){
producto=matrix[r][c]*matrix[r+1][c]*matrix[r+2][c]*matrix[r+3][c];
if (producto>max){
max=producto;
}
}
}
}
return max;
}

[8]ページ先頭

©2009-2025 Movatter.jp