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

[MIA] Martin G - functions and arrays#255

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
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.
53 changes: 53 additions & 0 deletionsstarter-code/src/functions-and-arrays.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
// Find the maximum
function maxOfTwoNumbers (num1, num2){
if (num1 > num2){
return num1;
}
else {
return num2;
}
}

// Finding Longest Word
var words = [
Expand All@@ -11,10 +19,37 @@ var words = [
'crackpot'
];

function findLongestWord (words){

var longest = words[0];

for (var i=1; i < words.length; i++) {

if (words[i].length > longest.length) {
longest = words[i];
}
}

return longest;

}

// Calculating a Sum

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

function sumArray (numbers) {
var total = 0
for (var i = 0; i < numbers.length; i++) {

total += numbers[i];

}

return total;

}

// Calculate the Average

var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];
Expand All@@ -33,6 +68,22 @@ var wordsArr = [
'palace'
];

function averageWordLength (wordsArr){

var total = 0;
var subTotal = 0;

for (var i = 0; i < wordsArr.length; i++) {

subTotal += wordsArr[i].length;
total = subTotal/wordsArr.length;

}

return total;

}

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



// Finding Elements
var wordsFind = [
'machine',
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp