mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
refactor(util) strCmp
This commit is contained in:
parent
676f2d17af
commit
f5174234f4
1 changed files with 14 additions and 21 deletions
35
lib/util.js
35
lib/util.js
|
|
@ -272,30 +272,23 @@
|
|||
* @param {String, Array} str2
|
||||
*/
|
||||
this.strCmp = function(str1, str2) {
|
||||
var length1, length2, isEqual,
|
||||
isStr = Util.isString(str1),
|
||||
var isEqual,
|
||||
type = Util.getType(str2);
|
||||
|
||||
if (isStr)
|
||||
switch(type) {
|
||||
case 'array':
|
||||
str2.some(function(str) {
|
||||
isEqual = Util.strCmp(str1, str);
|
||||
|
||||
return isEqual;
|
||||
});
|
||||
break;
|
||||
switch(type) {
|
||||
case 'array':
|
||||
str2.some(function(str) {
|
||||
isEqual = Util.strCmp(str1, str);
|
||||
|
||||
return isEqual;
|
||||
});
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
isEqual = str1 === str2;
|
||||
|
||||
case 'string':
|
||||
length1 = str1.length;
|
||||
length2 = str2.length;
|
||||
isEqual = length1 === length2;
|
||||
|
||||
if (isEqual)
|
||||
isEqual = !str1.indexOf(str2);
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return isEqual;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue