Create a function that accepts an object in the format {1: 4, 2: 10, 5:3} and outputs a list of numbers based on the key-value pairs in the object. Each pair specifies a number and how many times it should be included in the array.
Example: {3 : 10,5 : 2}
[3,3,3,3,3,3,3,3,3,3,5,5]
Handle cases where empty, null, undefined, or non-objects are passed into the function. In such scenarios, simply return an empty list, [].
Below is the code snippet I have been working on. I understand that a second loop is needed, but unsure about correctly populating the array with numbers as per their descriptions:
var numObj = {1:4, 2:10, 3:5};
function numDescribed(numObj) {
var numOfNums = [];
for (var x in numObj) {
numOfNums.push(numObj[x]); //this creates an array of [4, 10, 5]
}
for (var i = 0; i < numOfNums.length; i++) {
numOfNums.
}
}