Last active
August 29, 2015 14:24
-
-
Save jesusalber1/d262ce1c36da3ef13de0 to your computer and use it in GitHub Desktop.
Serialize name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Serialize names for cases when: | |
JESÚS ALBERTO POLO GARCÍA or POLO GARCÍA, JESÚS ALBERTO | |
I want the first one, then I modify the original String for get the first from the second (when necessary) | |
POLO GARCIA, JESUS ALBERTO -> JESUS ALBERTO POLO GARCIA */ | |
function serializeName(name) { | |
if (name.indexOf(',') > -1) { | |
var reversed = name.split(","); | |
reversed[0] = reversed[0].trim(); | |
reversed[1] = reversed[1].trim(); | |
name = reversed[1] + " " + reversed[0]; | |
} | |
return name; | |
} | |
/* Test: | |
var ok = "JESÚS ALBERTO POLO GARCÍA"; | |
var ko = "POLO GARCÍA, JESÚS ALBERTO"; | |
var name = serializeName(ok); | |
var name = serializeName(ko); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment