Had a search here but most answers seem to relate to Boolean values. I have a struct defined and initialised as below:
Struct Question {
var subjectID: Int
var questionID: Int
}
//Examples
let questionOne = Question(subjectID: 0, questionID: 0)
let questionTwo = Question(subjectID: 0, questionID: 1)
let questionThree = Question(subjectID: 0, questionID: 2)
let questionFour = Question(subjectID: 1, questionID: 0)
//An array populated with the above
var questions = [Question]()
I would like to find how to calculate:
1) The number of unique subjectID values in questions
Array. Answer should be 2.
2) The number of questions in questions
Array where subjectID == 0, or 1. Answer should be [3, 1].
I have explored with .filter
and .map
but perhaps I'm on the wrong tangent?
Thanks