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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!