scrimba
Note at 1:21
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 1:21
AboutCommentsNotes
Note at 1:21
Expand for more info
index.js
run
preview
console
import userData from "./data.js";

/* Totally Private Data Farm

Good news, renown advertising firm Evil Corp. wants to purchase our
private user data!

We'd never do this in real life of course, but just for practice
let's pretend we're unethical web hackers and transform the data
in the way Evil Corp. has requested. They're quite particular and
just want an array of users with a fullname and human readable
birthday.

Write a function that maps through the current data and returns
a new an array of objects with only two properties:
fullName and birthday. Each result in your
array should look like this when you're done:

{
fullName: "Levent Busser",
birthday: "Fri Aug 20 1971"
}

Read about toDateString() for info on formatting a readable date.

*/
function transformData(data){
// console.log(data[0]);
// console.log(data[0].name.first);
// console.log(data[0].name.last);
// console.log(data[0].dob.date)
const date = new Date (data[0].dob.date)
console.log(date.toDateString())

// const fullName = `${data[0].name.first} ${data[0].name.last}`;
// console.log(fullName);

const totallyPrivateDataArray = [];

const records = data.forEach((record) => {
const fullName = `${record.name.first} ${record.name.last}`;
const birthDate = new Date(record.dob.date);

const newRecord = {
fullName: fullName,
birthday: birthDate.toDateString()
};
totallyPrivateDataArray.push(newRecord);
});
return totallyPrivateDataArray;
}

console.log(transformData(userData));
Console
"Fri Aug 20 1971"
,
[
{fullName:
"Levent Busser"
, birthday:
"Fri Aug 20 1971"
}
,
{fullName:
"Kornelius Hamnes"
, birthday:
"Sat Sep 23 1961"
}
,
{fullName:
"Ute Henry"
, birthday:
"Sat Jun 30 1956"
}
,
{fullName:
"Estéfano Monteiro"
, birthday:
"Mon Jul 16 1945"
}
,
{fullName:
"Oğuzhan Beşerler"
, birthday:
"Sun Sep 28 1947"
}
,
{fullName:
"Susanna Burke"
, birthday:
"Tue Jun 13 1961"
}
,
{fullName:
"Haritya Starickiy"
, birthday:
"Fri Dec 14 1945"
}
,
{fullName:
"Nadja Branković"
, birthday:
"Mon May 24 1993"
}
,
{fullName:
"Sonja Lenzen"
, birthday:
"Wed Mar 21 1945"
}
,
{fullName:
"Shubhangi Chatterjee"
, birthday:
"Tue Dec 25 1956"
}
]
,
/index.html
LIVE