Last active
August 9, 2017 12:17
-
-
Save jamessergeant/15664cb71f50d3ef44ede1e42d565673 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
var max = -Infinity; | |
for (i=0; i < numbers.length; i++) { | |
max = max > numbers[i] ? max : numbers[i]; | |
} | |
return max | |
} | |
function min(numbers) { | |
var min = Infinity; | |
for (i=0; i < numbers.length; i++) { | |
min = min < numbers[i] ? min : numbers[i]; | |
} | |
return min | |
} | |
function average(numbers) { | |
var average = 0; | |
for (i=0; i < numbers.length; i++) { | |
average += numbers[i] / numbers.length; | |
} | |
return average | |
} | |
// probably less efficient than provided solution | |
function fizzBuzz(countTo) { | |
var fizzBuzzList = []; | |
for (i = 1; i <= countTo; i++) { | |
if ( (i % 3) && (i % 5)) fizzBuzzList.push(i); | |
if (!(i % 3) && (i % 5)) fizzBuzzList.push("fizz"); | |
if ( (i % 3) && !(i % 5)) fizzBuzzList.push("buzz"); | |
if (!(i % 3) && !(i % 5)) fizzBuzzList.push("fizzbuzz"); | |
} | |
return fizzBuzzList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment