My assignment is to print the first names of all individuals from a data set that fit a specific category; however, the data set is an array of objects that provides the full name as a string, e.g.:
var dataSet = [
{
"name": "John Doe",
"age": 60,
"math": 97,
"english": 63,
"yearsOfEducation": 4
},
{
"name": "Jane Doe",
"age": 55,
"math": 72,
"english": 96,
"yearsOfEducation": 10
}
]
I cannot use any array type built-in functions except filter(), map(), and reduce().
The last chunk of my code (to get names from the array of objects "dataSet") looks like:
var youngGoodMath = dataSet.filter(function(person){
return person.age < avgAge && person.math > avgMath;
});
var yGMname = youngGoodMath.map(function (person){
return person.name;
});
console.log(yGMname);
which produces an array of strings that looks something like:
["Jane Doe", "John Doe", "Harry Potter", "Hermione Granger"]
I need to find a way to produce:
["Jane", "John", "Harry", "Hermione"]
I suspect the answer lies in using .forEach and .Split(), but haven't been able to crack it yet...
return person.name.split(' ')[0]