Help me please with the playground exercise about data surveys

Imagine you work for Streaming Plus, a video streaming service. The marketing team wants to know how to spend their advertising budget. To help them decide, the company has provided a survey to users about their favorite shows. The survey lets users type the names of shows rather than showing them a very long scrolling list.

One of your teammates at Streaming Plus has created a Tabulator type that you can use to process the survey data. A tabulator records the number of times it sees each unique String value you hand to it. It has the following properties and methods:

values: [String]  A sorted array of the string values that have been tabulated.
func incrementCount(forValue value: String)  Increments the count for the given value. If that value hasn't been seen before, it's added to the values array and its count is set to 1.
func count(forValue value: String) -> Int  Returns the count for the given value. If that value has never been tabulated, the method will return 0.

On this page, you'll create an algorithm to tabulate the responses from this simulated survey and display the results. You'll use the same basic procedure in following pages.

There's a randomShowData array constant that simulates the results of a survey containing just 10 responses so you can test your code. It'll be different each time your code runs. (If you want, you can print the randomShowData to the console for verification.)

randomShowData
print(randomShowData)

Exercise: Using the comments as a guide, tally the survey results simulated in randomShowData.

This is my code but I am very not sure that I did it right

// Create a Tabulator instance.

var tabulator = Tabulator()

// Loop through the shows in randomShowData, incrementing the count for each one.

for i in 0 ... randomShowData.count - 1  {

    print(tabulator.incrementCount(forValue: randomShowData[i] ))

}

// Loop through the tallied shows (stored in tabulator.values), printing the information from each one.

for b in tabulator.values  {

    print(tabulator.count(forValue: b))

}

Please correct me if I did something wrong :)

Answered by Claude31 in 709446022

I'm not sure to understand your question. What do you get ? What do you expect ? Is that the correct result ?

Otherwise, code seems correct.

You could however change the first:

for show in randomShowData  {
    print(tabulator.incrementCount(forValue: show))
}
Accepted Answer

I'm not sure to understand your question. What do you get ? What do you expect ? Is that the correct result ?

Otherwise, code seems correct.

You could however change the first:

for show in randomShowData  {
    print(tabulator.incrementCount(forValue: show))
}
Help me please with the playground exercise about data surveys
 
 
Q