【发布时间】:2022-12-06 00:49:14
【问题描述】:
如何使下面的代码更简单?
这段代码中有一个if-else循环,但是能不能减少到最少的行数呢?
我们可以做些什么来降低这段代码的复杂性?
let android_devices = '';
let ios_devices = '';
let web_devices = '';
if (location_id == '') {
android_devices = await PRISMA.customers.count({
where: {
channel: 'ANDROID',
ref: headerData?.ref,
},
});
ios_devices = await PRISMA.customers.count({
where: {
channel: 'IOS',
ref: headerData?.ref,
},
});
web_devices = await PRISMA.customers.count({
where: {
channel: 'WEBSITE',
ref: headerData?.ref,
},
});
} else {
android_devices = await PRISMA.customers.count({
where: {
channel: 'ANDROID',
ref: headerData?.ref,
location_id: location_id,
},
});
ios_devices = await PRISMA.customers.count({
where: {
channel: 'IOS',
ref: headerData?.ref,
location_id: location_id,
},
});
web_devices = await PRISMA.customers.count({
where: {
channel: 'WEBSITE',
ref: headerData?.ref,
location_id: location_id,
},
});
}
【问题讨论】:
标签: javascript node.js