Titleify

by Scott Kaye

JavaScript

function titleify(str) {
  return str.split(/([A-Z]*)(?![a-z])/)
    .filter(Boolean)
    .join(" ");
}

let tests = ["SomeTest", "ABCTest", "somethingTest"];

tests.forEach(test => {
	console.log(titleify(test));
});