Hello,
My solution passes the self-test asserts as well as the unit tests that I wrote myself. But for some reason I get a "NoExecFunction" error on the 1st auto-tests.
Below is my code (also attached the .js files). Can someone tell me what I'm missing"
function frequencySort(items) {
let frequency = {}
let newArr = []
let arrSet = new Set()
const strNums = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
items.forEach((num) =>{
arrSet.add(num.toString(10));
});
items.forEach((item) => {
frequency[item] = frequency[item] ? frequency[item] + 1 : 1;
});
arrSet.forEach((num) => {
for (let i = 0; i < frequency[num]; i++) {
strNums.includes(num) ?
newArr.push(parseInt(num)) :
newArr.push(num);
}
});
if (items.length <= 1 || arrSet.size === items.length) {
return items;
} else {
return newArr;
}
}
Created at: 2022/07/19 22:57; Updated at: 2023/02/20 20:50
The question is resolved.