Skip to content

Instantly share code, notes, and snippets.

@elliotkim916
Created October 12, 2017 01:59
Show Gist options
  • Save elliotkim916/902c6565a7319a5973f17453c20e6891 to your computer and use it in GitHub Desktop.
Save elliotkim916/902c6565a7319a5973f17453c20e6891 to your computer and use it in GitHub Desktop.
Arrays and Loops Drills
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;
}
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;
}
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