diff --git a/exercises/addCommas/addCommas.js b/exercises/addCommas/addCommas.js index 7624a5d..80558b3 100644 --- a/exercises/addCommas/addCommas.js +++ b/exercises/addCommas/addCommas.js @@ -17,7 +17,7 @@ function sliceNumber(num){ let numberString = num.toString(); while (numberString.length >= 3){ parts.push(numberString.slice(-3)); - numberString = numberString.substring(0, numberString.length -3); + numberString = numberString.slice(0, -3); } if (numberString.length > 0){ parts.push(numberString); diff --git a/exercises/numberToEnglish/numberToEnglish.js b/exercises/numberToEnglish/numberToEnglish.js index 6f3ad62..9a04f28 100644 --- a/exercises/numberToEnglish/numberToEnglish.js +++ b/exercises/numberToEnglish/numberToEnglish.js @@ -111,7 +111,7 @@ function numberToEnglish(num) { } /// Join the strings in the descriptionWords array to form our result. - let result = descriptionWords.join(' '); + let result = descriptionWords.join(' ').trim(); /// Return the final result of the function return result; @@ -142,14 +142,14 @@ if (require.main === module) { // How else will you know if your code does what you expect, // or whether you've broken your existing code without realizing? - console.log(numberToEnglish(100) === 'one hundred '); + console.log(numberToEnglish(100) === 'one hundred'); console.log(numberToEnglish(0) === 'zero'); - console.log(numberToEnglish(10) === 'ten '); - console.log(numberToEnglish(419) === 'four hundred nineteen '); - console.log(numberToEnglish(1423) === 'one thousand four hundred twenty three '); + console.log(numberToEnglish(10) === 'ten'); + console.log(numberToEnglish(419) === 'four hundred nineteen'); + console.log(numberToEnglish(1423) === 'one thousand four hundred twenty three'); console.log(numberToEnglish(1000000) === 'one million'); - console.log(numberToEnglish(409) === 'four hundred nine '); - console.log(numberToEnglish(1000500) === 'one million five hundred '); + console.log(numberToEnglish(409) === 'four hundred nine'); + console.log(numberToEnglish(1000500) === 'one million five hundred'); } module.exports = numberToEnglish;