Swift - Data Types
Given a string
sentence, how can you create a dictionary mapping each unique Character to its count in the string?sentence, how can you create a dictionary mapping each unique Character to its count in the string?Dictionary(sentence.map { ($0, 1) }, uniquingKeysWith: +) uses Dictionary(_:uniquingKeysWith:) with + to sum counts correctly. Use sentence.reduce(into: [:]) { counts, char in counts[char] = 1 } overwrites counts instead of summing. Options A and D are invalid methods.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions