I have a function that returns a Set
And i need to iterate this set, but I found out that Set is not iterable so I convert it to array and now I'm getting this error type unknown cannot be used as an index type
Here is my code
let chosenDenominators = Array.from(MyLogic.randomUniqueDenominators(denominators, 3));
for (let i = 0; i < chosenDenominators.length; i++) {
console.log(denominators[chosenDenominators[i]]) //------- error here ---------
}
How to fix this issue?
EDIT:
static randomUniqueDenominators(denominators: number[], count: number) {
let nums = new Set();
let numerator = 0;
while ((nums.size < count)) {
numerator = Math.floor(Math.random() * denominators.length);
nums.add(numerator);
}
return nums;
}