execute: Optimize listIndex

This commit is contained in:
Thomas Weber committed 2020-09-09 22:03:56 -05:00
1 parent 80e0bccabc
commit e8d1e449a9
1 file changed
+2 -3
+2 -3
View File
@@ -346,17 +346,16 @@ const listIndex = (index, length) => {
return -1;
} else if (index === 'random' || index === '*') {
if (length > 0) {
return Math.floor(Math.random() * length);
return (Math.random() * length) | 0;
}
return -1;
}
index = +index || 0;
}
index = Math.floor(index);
if (index < 1 || index > length) {
return -1;
}
return index - 1;
return (index | 0) - 1;
};
/**