I am looking for a way to shorten Person and group names
Person :
Robert Smith
David Smith
James Johnson
William
If I use this code snippet:
if(Name.split(",").length === 1)
return Name.trim().split(" ").map(x => x[0]).reduce((acc, curr) => acc + curr)
else
return ''
The output will be:
- RS
- DS
- JJ
In another scenario, there are sets of names such as:
Robert Smith, David Smith
James Johnson, Robert Smith
In this case, if any comma is found, I would like to return RD
in the first case and JS
in the second case