CNCEC_APP/uni_modules/uview-pro/libs/function/randomArray.ts

12 lines
333 B
TypeScript
Raw Normal View History

2026-03-25 14:54:15 +08:00
/**
*
* @param array
* @returns
*/
function randomArray<T>(array: T[] = []): T[] {
// 原理是sort排序,Math.random()产生0<= x < 1之间的数,会导致x-0.5大于或者小于0
return array.sort(() => Math.random() - 0.5);
}
export default randomArray;