【发布时间】:2019-02-27 11:45:05
【问题描述】:
您好,我有一个 Book 类型对象数组,我正在尝试返回由 tags 属性过滤的所有 Books。例如
var books = [
(title = "The Da Vinci Code", tags = "Religion, Mystery, Europe"),
(title = "The Girl With the Dragon Tatoo", tags = "Psychology, Mystery, Thriller"),
(title = "Freakonomics", tags = "Economics, non-fiction, Psychology")
}]
我想找到与标签Psychology、(title = "The Girl With the Dragon Tatoo", tag = "Psychology, Mystery, Thriller") 和(title = "Freakonomics", tags = "Economics, non-fiction, Psychology") 关联的书籍,我该怎么做?
【问题讨论】:
-
从使用合适的数据模型开始。定义一个带有标题属性的结构体和一个字符串数组的标签属性。使用元组并将标签作为单个字符串是一种糟糕的数据模型选择,并且会使您的所有任务变得更加困难。