ds-algo-study
Version:
Just experimenting with publishing a package
33 lines (23 loc) • 875 B
JavaScript
/***********************************************************************
Write a function called `valuesInObject(obj)` that takes in an object and returns
an array of all the values within that Object.
Do this once using using a `for...in` loop and once using `Object.values`.
Examples:
let animals = {dog: "Wolfie", cat: "Jet", bison: "Bilbo"}
let foods = {apple: "tart", lemon: "sour", mango: "sweet"}
valuesInObject(animals); // => ["Wolfie", "Jet", "Bilbo"]
valuesInObject(foods); // => ["tart", "sour", "sweet"]
***********************************************************************/
function valuesInObject(obj) {
return Object.values(obj);
}
// solution 2
// function valuesInObject(obj) {
// let array = [];
// for (key in obj) {
// let value = obj[key];
// array.push(value);
// }
// return array;
// }
module.exports = valuesInObject;