Created
July 17, 2019 10:30
-
-
Save sayanriju/15614ff537b046734c320254ffdf4f45 to your computer and use it in GitHub Desktop.
A simple function to split given Full Name into components First, Middle & Last
This file contains hidden or 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
function splitName(full) { | |
const arr = full.split(" ").filter(c => c !== "") | |
const first = arr.shift() | |
const last = arr.pop() | |
const middle = arr.join(" ") || undefined | |
return { first, middle, last } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment