write function takes list of values , returns dictionary in format below
sample input: [“book”, 3, “pin”, 3.5] sample output { string :[“book”, “pin”], number:[3,5] } */
above code challenge question , dont know start understand dictionary key/value js fucnction.. have tried following
var dict = []; // create empty array dict.push({ string: ["book" , "pin"] , number: [3 , 4] }); // repeat last part needed add more key/value pairs console.log(dict)..
it displays output need im not sure process correct
something this?
var list = ["book", 3, "pin", 4]; function toobject(arr){ var dict = { string: [], number: [] }; for( var = 0; < arr.length; i++ ){ if( typeof arr[i] === "string"){ dict.string.push(arr[i]); } else { dict.number.push(arr[i]); } } return dict; } toobject(list);
Comments
Post a Comment