Tell us what’s happening:
As per the question i should only remove the element that passed with the array… the output is correct the only thing stopping it from passing is that the order of output is not matching.
The question does not say to maintain the order anywhere
eg:
destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3)
the test expect to return [1,5,1]
but my code [1,1,5]
destroyer(["possum", "trollo", 12, "safari", "hotdog", 92, 65, "grandma", "bugati", "trojan", "yacht"], "yacht", "possum", "trollo", "safari", "hotdog", "grandma", "bugati", "trojan")
the test expect [12,92,65]
but my code [12,65,92]
**Your code so far**
function destroyer(arr) {
const obj = {}
arr.forEach(value => {
obj[value] = obj[value] ? ++obj[value] : 1
})
const deleteEl = Array.from(arguments).slice(1)
deleteEl.forEach(value => {
delete obj[value]
})
let newArr = []
console.log(obj)
for (let key in obj) {
let toStore = parseInt(key)
if (typeof toStore === 'number' && !isNaN(toStore)) {
newArr = newArr.concat(Array(obj[key]).fill(toStore))
} else {
newArr = newArr.concat(Array(obj[key]).fill(key))
}
}
console.log(newArr);
return newArr;
}
destroyer(["possum", "trollo", 12, "safari", "hotdog", 92, 65, "grandma", "bugati", "trojan", "yacht"], "yacht", "possum", "trollo", "safari", "hotdog", "grandma", "bugati", "trojan");
// destroyer([2, 3, 2, 3], 2, 3);
// destroyer(["tree", "hamburger", 53], "tree", 53)
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0
Challenge: Seek and Destroy
Link to the challenge: