add isAllchar func

This commit is contained in:
Gabe Yuan
2023-09-07 10:20:08 +08:00
parent 08e14ae11c
commit da13f5e218
2 changed files with 20 additions and 9 deletions

View File

@@ -57,6 +57,23 @@ export const debounce = (func, delay = 200) => {
};
};
/**
* 判断字符串全是某个字符
* @param {*} s
* @param {*} c
* @param {*} i
* @returns
*/
export const isAllchar = (s, c, i = 0) => {
while (i < s.length) {
if (s[i] !== c) {
return false;
}
i++;
}
return true;
};
/**
* 字符串通配符(*)匹配
* @param {*} s
@@ -91,14 +108,7 @@ export const isMatch = (s, p) => {
return true;
}
while (pIndex < p.length) {
if (p[pIndex] !== "*") {
return false;
}
pIndex++;
}
return true;
return isAllchar(p, "*", pIndex);
};
/**