Created
October 12, 2017 01:59
-
-
Save elliotkim916/902c6565a7319a5973f17453c20e6891 to your computer and use it in GitHub Desktop.
Arrays and Loops Drills
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function average(numbers) { | |
// your code goes here | |
var total = 0; | |
for (let i = 0; i < numbers.length; i++) { | |
total += numbers[i]; | |
} | |
return total / numbers.length; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fizzBuzz(countTo) { | |
// your code here | |
var values = []; | |
for (var i = 1; i <= countTo; i++) { | |
if (i % 5 === 0 && i % 3 === 0) { | |
values.push('fizzbuzz'); | |
} | |
else if (i % 5 === 0) { | |
values.push('buzz'); | |
} | |
else if (i % 3 === 0) { | |
values.push('fizz'); | |
} | |
else { | |
values.push(i); | |
} | |
} | |
return values; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function max(numbers) { | |
// your code here | |
var gr = 0; | |
for (let i = 0; i < numbers.length; i++ ) { | |
if (numbers[i] > gr) { | |
gr = numbers[i]; | |
} | |
} return gr; | |
} | |
function min(numbers) { | |
// your code here | |
var sm = 0; | |
for (let i = 0; i < numbers.length; i++) { | |
if (numbers[i] < sm) { | |
sm = numbers[i]; | |
} | |
} return sm; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment