0
Distinct values confusion
Why is the code not seeing the additional items? function main() { let products = new Set([ "dumbbells", "barbell", "t-shirt", "swim short", "gloves", "training apparatus", "goggle", ]); var count = 0; while(count<3, count++){ var itemType = readLine(); //add the item to the set products.add(itemType); } //calculate and output the count of item types for (let count of set.products()) console.log(products.size); }
3 Respuestas
+ 4
The while-loop is mistakenly constructed.
while( count < 3 )
{
// code here
count++;
}
Or alternatively,
while( count++ < 3 )
{
// code here
}
I'm not sure what you're trying to do with the for-each loop at the bottom. As I understand it, `Set` stores unique data, so every `Set` entry should be unique (no duplicates).
I don't think it is a good idea to use a `Set` for counting frequency of data.
(Edited)
+ 2
Thank Ipang!
I tried the first loop from the previous example as a shot in the dark.
✔
+ 2
Keep trying and good luck! 👍