【发布时间】:2020-01-29 21:35:28
【问题描述】:
我有两个Array 的问题。我必须比较才能仅在必要时创建,否则更新。
这是我的代码:
const issueList = [
"Ajout de google analytics",
"Déployement en continue dev",
"Déployement en continue préproduction",
"Déployement en continue production",
"Déployment ipa automatique sur app store",
"Déployment apk automatique sur play store"
];
const existingIssueList = [
"Déployement en continue production",
"Déployement en continue préproduction",
"List swipe web"
];
for (let i = 0; i < issueList.length; i += 1) {
let issueFound = null;
for (let j = 0; j < existingIssueList.length; j += 1) {
if (issueList[i] === existingIssueList[j]) {
issueFound = existingIssueList[j];
break;
}
}
// If issue was found, we do not need to create theissue
let issue;
if (issueFound) {
issue = updateIssue({
issue: issueFound,
});
console.log(`issue has been updated`);
} else {
issue = createIssue({
issue: issueList[i],
});
console.log(`issue has been created`);
}
}
function updateIssue(){}
function createIssue(){}
我希望找到重复的值并更新它们,我在哪里失败了?
【问题讨论】:
-
会发生什么?请添加想要的结果。
-
如果您必须经常在长数组中查找字符串,请改用
Set,因为它查找速度很快。
标签: javascript arrays node.js compare