Skip to content

Instantly share code, notes, and snippets.

@jesusalber1
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusalber1/d262ce1c36da3ef13de0 to your computer and use it in GitHub Desktop.
Save jesusalber1/d262ce1c36da3ef13de0 to your computer and use it in GitHub Desktop.
Serialize name
/* 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