Answers for "format string of names"

0

format string of names

function list(names) {
  var xs = names.map((p) => p.name);
  var x = xs.pop();
  return xs.length ? xs.join(", ") + " & " + x : x || "";
}

// Example:
// list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ])
// returns 'Bart, Lisa & Maggie'
Posted by: Guest on August-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language