update var to const in function declarations

This commit is contained in:
Michael Frank 2021-05-10 00:06:18 +12:00
parent ce0b9fade1
commit a5a0284ac1
8 changed files with 16 additions and 16 deletions

View File

@ -1,26 +1,26 @@
function add(a, b) { const add = function(a, b) {
return a + b; return a + b;
} }
function subtract(a, b) { const subtract = function(a, b) {
return a - b; return a - b;
} }
function sum(array) { const sum = function(array) {
return array.reduce((total, current) => total + current, 0); return array.reduce((total, current) => total + current, 0);
} }
function multiply(array) { const multiply = function(array) {
return array.length return array.length
? array.reduce((accumulator, nextItem) => accumulator * nextItem) ? array.reduce((accumulator, nextItem) => accumulator * nextItem)
: 0; : 0;
} }
function power(a, b) { const power = function(a, b) {
return Math.pow(a, b); return Math.pow(a, b);
} }
function factorial(n) { const factorial = function(n) {
if (n == 0) return 1; if (n == 0) return 1;
let product = 1; let product = 1;
for (let i = n; i > 0; i--) { for (let i = n; i > 0; i--) {
@ -31,7 +31,7 @@ function factorial(n) {
// This is another implementation of Factorial that uses recursion // This is another implementation of Factorial that uses recursion
// THANKS to @ThirtyThreeB! // THANKS to @ThirtyThreeB!
function recursiveFactorial(n) { const recursiveFactorial = function(n) {
if (n===0){ if (n===0){
return 1; return 1;
} }

View File

@ -1,4 +1,4 @@
var getTheTitles = function(array) { const getTheTitles = function(array) {
return array.map(book => book.title) return array.map(book => book.title)
} }

View File

@ -1,4 +1,4 @@
var helloWorld = function() { const helloWorld = function() {
return 'Hello, World!' return 'Hello, World!'
} }

View File

@ -1,4 +1,4 @@
var leapYears = function(year) { const leapYears = function(year) {
return year % 4 === 0 && ( year % 100 !== 0 || year % 400 == 0) return year % 4 === 0 && ( year % 100 !== 0 || year % 400 == 0)
} }

View File

@ -1,4 +1,4 @@
function pigLatin(string) { const pigLatin = function(string) {
return string return string
.split(" ") .split(" ")
.map(word => { .map(word => {
@ -10,7 +10,7 @@ function pigLatin(string) {
.join(" "); .join(" ");
} }
function firstVowelIndex(string) { const firstVowelIndex = function(string) {
const vowels = string.match(/[aeiou]/g); const vowels = string.match(/[aeiou]/g);
if (vowels[0] == "u" && string[string.indexOf(vowels[0]) - 1] == "q") { if (vowels[0] == "u" && string[string.indexOf(vowels[0]) - 1] == "q") {
return string.indexOf(vowels[1]); return string.indexOf(vowels[1]);

View File

@ -1,4 +1,4 @@
var repeatString = function(word, times) { const repeatString = function(word, times) {
if (times < 0) return 'ERROR' if (times < 0) return 'ERROR'
let string = '' let string = ''
for (let i = 0; i < times; i++) { for (let i = 0; i < times; i++) {

View File

@ -1,4 +1,4 @@
var reverseString = function(string) { const reverseString = function(string) {
return string.split('').reverse().join('') return string.split('').reverse().join('')
} }

View File

@ -1,8 +1,8 @@
var ftoc = function(f) { const ftoc = function(f) {
return Math.round((f - 32) * (5/9) * 10) / 10 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 return Math.round(((c * 9/5) + 32) * 10) / 10
} }