tracks/ecmascript/exercises/perfect-numbers/example.js in trackler-2.1.0.25 vs tracks/ecmascript/exercises/perfect-numbers/example.js in trackler-2.1.0.26

- old
+ new

@@ -12,21 +12,21 @@ let divs = new Array(); // Accepts only natural numbers greater than 1. if (number <= 1) { return divs; - } + } // 1 always divides everyone! divs.push(1); // Calculate the divisors up the the half of the number + 1 for (i = 2; i <= number / 2; i++) { if (number % i === 0) { divs.push(i); - } + } } return divs; } @@ -36,11 +36,11 @@ * then returns an error: Classification is only possible for natural numbers. * @returns {string} - string that contains the number classification (perfect, abundant or deficient). */ classify(number) { - let i, sum, result; + let sum, result; // Check if the input is valid if (number <= 0) { throw new Error('Classification is only possible for natural numbers.'); } @@ -52,14 +52,12 @@ sum = divsArray.reduce((sum, div) => sum += div, 0); // Check if the number is perfect. if (sum === number) { result = 'perfect'; - } - else if (sum > number) { + } else if (sum > number) { result = 'abundant'; - } - else { + } else { result = 'deficient'; } return result; }