thatadamedwards
04/19/2018, 7:29 PMit("kotlin slack") {
val dictionary = mutableMapOf("fruits" to mutableSetOf("apple", "banana", "orange", "cherry"))
fun putValueInAppropriateCategory(value: String, key: String, map: MutableMap<String, MutableSet<String>>) {
if (map.contains(key)) {
map[key]?.plusAssign(value)
} else {
map[key] = mutableSetOf(value)
}
}
putValueInAppropriateCategory("strawberry", "fruits", dictionary)
putValueInAppropriateCategory("carrot", "vegetables", dictionary)
dictionary["fruits"].should.contain("strawberry")
dictionary.containsKey("vegetables").should.be.`true`
dictionary["vegetables"].should.contain("carrot")
}