diff --git a/calculator/calculator.js b/calculator/calculator.js index fe548f7..57ed93e 100644 --- a/calculator/calculator.js +++ b/calculator/calculator.js @@ -1,26 +1,26 @@ -function add(a, b) { +const add = function(a, b) { return a + b; } -function subtract(a, b) { +const subtract = function(a, b) { return a - b; } -function sum(array) { +const sum = function(array) { return array.reduce((total, current) => total + current, 0); } -function multiply(array) { +const multiply = function(array) { return array.length ? array.reduce((accumulator, nextItem) => accumulator * nextItem) : 0; } -function power(a, b) { +const power = function(a, b) { return Math.pow(a, b); } -function factorial(n) { +const factorial = function(n) { if (n == 0) return 1; let product = 1; for (let i = n; i > 0; i--) { @@ -31,7 +31,7 @@ function factorial(n) { // This is another implementation of Factorial that uses recursion // THANKS to @ThirtyThreeB! -function recursiveFactorial(n) { +const recursiveFactorial = function(n) { if (n===0){ return 1; } diff --git a/getTheTitles/getTheTitles.js b/getTheTitles/getTheTitles.js index d932e81..8f8fe80 100644 --- a/getTheTitles/getTheTitles.js +++ b/getTheTitles/getTheTitles.js @@ -1,4 +1,4 @@ -var getTheTitles = function(array) { +const getTheTitles = function(array) { return array.map(book => book.title) } diff --git a/helloWorld/helloWorld.js b/helloWorld/helloWorld.js index 9029bef..7d01115 100644 --- a/helloWorld/helloWorld.js +++ b/helloWorld/helloWorld.js @@ -1,4 +1,4 @@ -var helloWorld = function() { +const helloWorld = function() { return 'Hello, World!' } diff --git a/leapYears/leapYears.js b/leapYears/leapYears.js index f6b3e00..4a8d8d2 100644 --- a/leapYears/leapYears.js +++ b/leapYears/leapYears.js @@ -1,4 +1,4 @@ -var leapYears = function(year) { +const leapYears = function(year) { return year % 4 === 0 && ( year % 100 !== 0 || year % 400 == 0) } diff --git a/pigLatin/pigLatin.js b/pigLatin/pigLatin.js index 3ba465d..75f4c2a 100644 --- a/pigLatin/pigLatin.js +++ b/pigLatin/pigLatin.js @@ -1,4 +1,4 @@ -function pigLatin(string) { +const pigLatin = function(string) { return string .split(" ") .map(word => { @@ -10,7 +10,7 @@ function pigLatin(string) { .join(" "); } - function firstVowelIndex(string) { +const firstVowelIndex = function(string) { const vowels = string.match(/[aeiou]/g); if (vowels[0] == "u" && string[string.indexOf(vowels[0]) - 1] == "q") { return string.indexOf(vowels[1]); diff --git a/repeatString/repeatString.js b/repeatString/repeatString.js index b300278..36fd49c 100644 --- a/repeatString/repeatString.js +++ b/repeatString/repeatString.js @@ -1,4 +1,4 @@ -var repeatString = function(word, times) { +const repeatString = function(word, times) { if (times < 0) return 'ERROR' let string = '' for (let i = 0; i < times; i++) { diff --git a/reverseString/reverseString.js b/reverseString/reverseString.js index bbab5c1..87c3cc6 100644 --- a/reverseString/reverseString.js +++ b/reverseString/reverseString.js @@ -1,4 +1,4 @@ -var reverseString = function(string) { +const reverseString = function(string) { return string.split('').reverse().join('') } diff --git a/tempConversion/tempConversion.js b/tempConversion/tempConversion.js index 742d8e2..8db2e9e 100644 --- a/tempConversion/tempConversion.js +++ b/tempConversion/tempConversion.js @@ -1,8 +1,8 @@ -var ftoc = function(f) { +const ftoc = function(f) { return Math.round((f - 32) * (5/9) * 10) / 10 } -var ctof = function(c) { +const ctof = function(c) { return Math.round(((c * 9/5) + 32) * 10) / 10 }