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) { | |
var newCountTo = []; | |
for (var i =1; i<= countTo; i++){ | |
// if (i%3 !==0 && i%5 !==0){ | |
// newCountTo.push(i); | |
// } | |
//compare countTo[i] to 15 and chg countTo[i] to fizzBuzz | |
if (i%3 ===0 && i%5 ===0){ |
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) { | |
console.log("initial countTo = ", countTo); | |
var newCountTo = []; | |
for (var i =0; i< countTo.length; i++){ | |
//compare countTo[i] to 15 and chg countTo[i] to fizzBuzz | |
if (countTo[i]%3 ==0 && countTo[i]%5 ==0){ | |
newCountTo[i] = 'fizzbuzz'; | |
} |
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) { | |
var newCountTo = []; | |
for (var i =1; i<= countTo.length; i++){ | |
//compare countTo[i] to 3 and chg countTo[i] to fizz | |
if (countTo[i]%3 ===0){ | |
newCountTo[i] = 'fizz'; | |
} | |
//compare countTo[i] to 5 and chg countTo[i] to buzz | |
if (countTo[i]%5 ===0){ |
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) { | |
//Performing task without looping: | |
// return (numbers.reduce(function sum(total, num){ | |
// return total + num; | |
// })/numbers.length); | |
// Second way to perform with loop | |
var maxNum = numbers[0]; | |
for (var i =1; i<= numbers.length -1; i++){ | |
maxNum += numbers[i]; |
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) { | |
return (numbers.reduce(function sum(total, num){ | |
return total + num; | |
})/numbers.length); | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
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) { | |
var maxNum = 0; | |
for (var i =1; i<= numbers.length; i++){ | |
if (maxNum <= numbers[i]){maxNum = numbers[i]; | |
} | |
} | |
return maxNum; | |
} | |
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 shortWords(array) { | |
return array.filter(function lessFive(x){ | |
return x.length <5; | |
}); | |
} | |
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 divisibleBy5(array) { | |
return array.find(function fiveDiv(x){ | |
return x % 5===0; | |
}); | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
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 greatestToLeast(array) { | |
//array.sort(function(a, b) { return b-a; }); descending order | |
return array.sort(function(a,b){ | |
return b-a; | |
}); | |
} | |
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 squares(array) { | |
return array.map(function(x){ | |
return Math.pow(x,2); | |
}) | |
} | |