Question: JavaScript Write a function named extractNames that extracts the first name and last name from a given name. The function accepts a string and returns
JavaScript
Write a function named extractNames that extracts the first name and last name from a given name.
- The function accepts a string and returns an array that stores the first then last name.
- Assume that the given first and the last name is separated by a single white space.
- You should test your function and it should pass the following two tests
Test cases:
console.log(extractNames('John Doe'));
console.log(extractNames('Mary Smith'));
Returns:
[ 'John', 'Doe' ] [ 'Mary', 'Smith' ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
