twhite96
6/24/2017 - 4:44 AM

algorithm functions from The Web Developer Bootcamp

algorithm functions from The Web Developer Bootcamp

function isEven(num) {
  if (num % 2 === 0) {
    return true;
  }
  return false;
}

// Refactor

function isEven(num) {
  return num % 2 === 0;
}

// Calculate factorial

function factorial(x) {
  if (x === 0) {
    return 1;
  }
  return x * factorial(x - 1);
}

function kebab(str) {
  var array = str.split("-");
  var joinedString = array.join("_");
  return joinedString;
}

// Refactor

function kebab(str) {
  var newString =  str.replace(/-/g, "_");
  return newString;
}

isEven(8);
isEven(3);

factorial(8);

kebab("I-am-a-fool");