Skip to content

Instantly share code, notes, and snippets.

@igeligel
Created June 8, 2019 20:17
Show Gist options
  • Save igeligel/5d09207609298dd1b28fcf2729b3a320 to your computer and use it in GitHub Desktop.
Save igeligel/5d09207609298dd1b28fcf2729b3a320 to your computer and use it in GitHub Desktop.
const vehicles = [
"Airbus A333-300",
"Volkswagen Golf",
"Porsche Cayenne",
"Airbus A380-800"
];
const vehiclesWithTypes = vehicles.map(vehicle => {
switch (vehicle) {
case "Airbus A380-800":
case "Airbus A333-300":
return {
name: vehicle,
type: "airplane"
};
break;
case "Volkswagen Golf":
case "Porsche Cayenne":
return {
name: vehicle,
type: "car"
};
default:
return {
name: vehicle,
type: null
};
}
});
console.log(vehiclesWithTypes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment