LName FName to FName LName

by Matthew Day

JavaScript

var pre = "Smith, Stanley",
		// split makes an array
    // reverse swaps the position of the elements in the array
    // join converts the array to a string
    post = pre.split(", ").reverse().join(" ");
    // this if block removes anything that is not a first or last name
		if(name.split(" ").length > 2) {
    	name = name.split(" ");
    	name.splice(1, 1);
    	name = name.join(" ");    
		}
console.log(post);



// SOURCES
// http://jsfiddle.net/6AdGs/