1 回答
TA贡献1847条经验 获得超7个赞
const checkedItems = [
'12345|PRC-3343',
'12345|FELMP',
'567892|PRC-3343',
'567892|FEIIO',
'12345|PCNOWAY'
];
function validateForm(checkedItems: string[]): boolean {
const parsedCheckedItems = parseValues(checkedItems);
return !checkDups(parsedCheckedItems);
}
function parseValues(checkedItems: string[]): string[] {
return checkedItems.map(item => {
const pipeIdx = item.indexOf('|');
return item.substr(1, pipeIdx + 1);
});
}
function checkDups(parsedCheckedItems: string[]): boolean {
return new Set(parsedCheckedItems).size !== parsedCheckedItems.length;
}
const formValid = validateForm(checkedItems);
console.log(formValid);
添加回答
举报