Javascript – How to Create Functions to replace text, factorial, check if it’s even

These are some code snippets on how to create functions to check if a number is even. Do a factorial with a for loop. Do a text replacement with regular expressions.

// isEven f(x)
function isEven(arg) {
	return arg%2 === 0
}
// factorial f(x)
function factorial(num) {
	var result = 1;
	for(var i = 2; i <= num; i++) {
		result = result * i;
	}
	return result;
}
// kebabToSnake() Replace a string "-" with '_'s
function kebabToSnake(str) {
	var newStr = str.replace(/-/g , "_");
	return newStr;
}