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 Hannah Loop#447

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
hloop wants to merge1 commit intoironhack-labs:masterfromhloop: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.
Binary file addedstarter-code/src/.DS_Store
View file
Open in desktop
Binary file not shown.
137 changes: 137 additions & 0 deletionsstarter-code/src/LabJavaScript.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
// Find the Maximum
function maxOfTwoNumbers (num1, num2) {
if (num1 > num2) {
console.log('The maximum number is ' + num1);
} else if (num1 < num2) {
console.log('The maximum number is ' + num2);
} else {
console.log('They\'re the same!');
}
}

maxOfTwoNumbers (prompt('Type your first number'), (prompt('Type your second number')));



// Find The Largest Word
var words = [
'mystery',
'brother',
'aviator',
'crocodile',
'pearl',
'orchard',
'crackpot'
];

function findLongestWord(wordsArray) {
var longestWord = '';

wordsArray.forEach(function(eachWord){
if(eachWord.length > longestWord.length) {
longestWord = eachWord;
}
});
return longestWord;
}

console.log (findLongestWord(words));



// Calculating a Sum
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10].reduce(function (accumulator, currentValue) {
return accumulator + currentValue;
}, 0);
console.log(numbers);

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

function calculateSum(arrayOfNumbers) {
var sum = 0;

arrayOfNumbers.forEach(function(oneParticularNumber) {
sum += oneParticularNumber
});
return sum;
}

console.log(calculateSum(numbers));



// Calculate the Average
function calculateAverage(numberArray) {
return (calculateSum(numberArray) / numberArray.length)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Reusing previously defined functions is a smart move. Good call!

}

console.log(calculateAverage())



// Unique Arrays
var wordsWithDuplicates = [
'crab',
'poison',
'contagious',
'simple',
'bring',
'sharp',
'playground',
'poison',
'communion',
'simple',
'bring'
];

function uniquifyArray(theArray) {
if(theArray.length < 1) {
return undefined;
}
var newArray = [];

wordsWithDuplicates.forEach(function(eachWord) {

if(newArray.indexOf(eachWord) === -1) {
newArray.push(eachWord)
}
});

return newArray

console.log(uniquifyArray(wordsWithDuplicates));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thisconsole.log() has to be outside of this} braces.

}



// Finding Elements
function doesItExist(arrayOfWords, wordToSearchFor) {
var doesIt = false;

arrayOfWords.forEach(function(eachWord) {
if(eachWord === wordToSearchFor) {
doesIt = true
}
});
return doesIt
}

console.log(doesItExist(wordsWithDuplicates, 'crab')); //change last string to test loop



// Counting Repetition
function numberOfTimes(theArray, word) {
var count = 0;

theArray.forEach(function(eachWord) {
if(eachWord === theWord) {
count++
}
});

return count;
}

console.log(numberOfTimes(wordsWithDuplicates, 'rain'));
100 changes: 0 additions & 100 deletionsstarter-code/src/functions-and-arrays.js
View file
Open in desktop

This file was deleted.


[8]ページ先頭

©2009-2025 Movatter.jp