Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

let fullname = ['Larry Gordon', 'Mariem Elasri', 'Harry Potter', 'Mary

Butterworth'];

function split(fullname) {
const spaceIndex = fullname.indexOf(' ');
const firstName = fullname.slice(0, spaceIndex);
const lastName = fullname.slice(spaceIndex + 1);

return { firstName, lastName };


}

function reverseFullName(fullname) {
const { firstName, lastName } = split(fullname);
return 'Reversed name: ' + lastName + ', ' + firstName;
}

function formatGreeting(fullname) {
const { firstName, lastName } = split(fullname);
const firstInitial = firstName.charAt(0);
return 'Greeting: Dear ' + firstInitial + '. ' + lastName;
}

fullname.forEach(function(name) {
console.log('Name being processed : ', name);
console.log(split(name));
console.log(reverseFullName(name));
console.log(formatGreeting(name));
console.log(' ');
});

You might also like