If we consider a scenario where an array of names is provided,
let names = [
[
['firstName', 'Rachel'],
['age', 10],
['gender', 'female'],
],
[
['firstName', 'Sam'],
['lastName', 'Smith'],
['age', 20],
['gender', 'male'],
],
];
The desired output would resemble the code snippet below.
let output = nameInOrder(names);
console.log(output); // --> ['Rachel', 'Sam Smith'];
In order to successfully implement the nameInOrder function,
function nameInOrder(arr) {
// insert code here
}
Would it be appropriate to start with the .map
method for transforming the data into objects within an array, then utilize sort(a,b)
and .join(' ')
? How should they be sorted in ascending order?