Skip to content

Latest commit

 

History

History
63 lines (30 loc) · 632 Bytes

004.md

File metadata and controls

63 lines (30 loc) · 632 Bytes

We have a function getUser, that when given an id will attempt to return a user. If successful, the user will look like: [ "success"/*, name, age, favouriteLanguage */ ]. We want to return something that looks like

{/*
  name,
  age,
  favouriteLang,
  dateRetrieved
*/}

Let's do it!

function getUserRecord (id) {
  var user = getUser(id)
  return {
    name: user[1],
    age: user[2],
    favouriteLang: user[3],
    dateRetrieved: new Date
  }

}

console.log(getUserRecord(4))


























function getUser (id) {
  return [ "success", "Jigglypuff", Infinity, "JavaScript" ]
}