import Foundation

class Course {
  let name: String
  let students: [String]

  init(name: String, students: [String]) {
    self.name = name
    self.students = students
  }
}

let courses = [
  Course(name: "M323", students: ["Peter", "Petra", "Paul", "Paula"]),
  Course(name: "M183", students: ["Paula", "Franz", "Franziska"]),
  Course(name: "M117", students: ["Paul", "Paula"]),
  Course(name: "M114", students: ["Petra", "Paul", "Paula"]),
]

// print(
//     courses.map {
//         return $0.students
//     }.filter {
//         $0.contains("Peter")
//     }.count
// )

// print(
//     courses.map {
//         return $0.students
//     }.filter {
//         $0.contains("Petra")
//     }.count
// )

func studentAttendsCourse(studentName: String, courses: [Course]) -> String {
  let visitedCourses = courses.map {
    return ($0.name, $0.students)
  }.filter {
    $0.1.contains(studentName)
  }.map {
    return $0.0
  }
  return
    "\(studentName) visits the following courses: \(visitedCourses.joined(separator: ", "))"
}
