Ad
Code
Diff
  • const isDivisible = (n,x,y) => (!(n%x) && !(n%y))
    • function isDivisible(n, x, y) {
    • if (n % x === 0 && n % y === 0) {
    • return true
    • } else {
    • return false
    • }
    • }
    • const isDivisible = (n,x,y) => (!(n%x) && !(n%y))
Code
Diff
  • const power = (num, exp) => !exp ? 1 : new Array(exp).fill(num).reduce((a , b) => a * b)
    • function power(num,exp){
    • if(exp === 0){
    • return 1;
    • }
    • if(exp % 2 === 0){
    • let half = Math.floor(exp/2)
    • return power(num, half) * power(num, half);
    • }else{
    • let half = Math.floor((exp-1)/2)
    • return num * power(num, half) * power(num, half);
    • }
    • }
    • const power = (num, exp) => !exp ? 1 : new Array(exp).fill(num).reduce((a , b) => a * b)
Code
Diff
  • const factorial = num => num === 1 ? 1 : num * factorial(num - 1)
    • function factorial(num){
    • if(num === 1){
    • return 1;
    • }
    • return num * factorial(num - 1)
    • }
    • const factorial = num => num === 1 ? 1 : num * factorial(num - 1)