【发布时间】:2019-06-15 13:19:11
【问题描述】:
我很尴尬地发布这个,但我真的可以在这里使用。这段代码看起来很糟糕。我有一种感觉,我可以用filter 或reduce 编写更简洁的方法,但似乎无法刺伤它。有什么想法吗,社区?
const vin = detections.map(detection => {
return detection.textAnnotations.map(v => {
let n = v.description.replace(/\s+/g, '');
if (n.length === 17) {
return n;
}
});
})[0][0];
谢谢!
【问题讨论】:
-
好吧,对于初学者来说,不要不好意思发布代码,否则您将无法通过社区的投入来改进!
-
为什么是两个
.maps?为什么不直接选择其中的第一个detection和第一个textAnnotations,然后适当替换,完全不循环? -
@NikKyriakides 实际上,即使在 CR:codereview.stackexchange.com/help/dont-ask 和 codereview.stackexchange.com/help/on-topic,也不应该问这个问题。它没有勾选大多数方框。但是好吧,让 OP 在那里问它,让我们看看会发生什么......
-
@GerardoFurtado 我坚持
标签: javascript filter reduce