Add spaces to a string

by Matthew Day

JavaScript

let nospaces = 'JoeKlein';

var map = Array.prototype.map;

let arr = map.call(nospaces, (item, index) => {
	if(index === 0 && item.charAt(0).match(/[A-Z]/)) {
  	return `${item}`;
  } else if(item.charAt(0).match(/[A-Z]/)) {
  	return ` ${item}`;
  } else {
  	return item;
  }
});

console.log(arr.join(''));