Task: Name Clean Up

n8n workflow:
{"nodes":[{"name":"Extract First Last Name","type":"n8n-nodes-base.functionItem","position":[740,300],"parameters":{"functionCode":"function startcase(str){\n// does contain space\nif (str.indexOf(' ') >= 0)\n{\n var strings = str.split(' ');\n // loop through words\n for (var i=0; i < strings.length;i++)\n {\n // startcase word in array\n strings[i] = strings[i].charAt(0).toUpperCase() + strings[i].slice(1);\n }\n //rejoin array into string, seperated by space\n return strings.join(' ')\n}else{\n// if no space, sentence case one word\nreturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n}\n\n\nvar string = item.name;\n\n// Startcase\nstring = startcase(string);\nvar strings;\n\n// check if contains space\nif (string.indexOf(' ') >= 0)\n{\n// split string by space\nstrings = string.split(' ');\nitem.title_name = strings[0];\nitem.first_name = strings[1];\nitem.last_name =  strings[2];\n}else\n// If not contain name, then set full_name to first name\n{\nitem.first_name = item.name;\n}\n\nreturn item;\n"},"typeVersion":1,"alwaysOutputData":false},{"name":"Set","type":"n8n-nodes-base.set","position":[550,300],"parameters":{"values":{"string":[{"name":"name","value":"mr john smith"}]},"options":{}},"typeVersion":1}],"connections":{"Set":{"main":[[{"node":"Extract First Last Name","type":"main","index":0}]]}}}