当前位置:网站首页>JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
2022-07-02 09:32:00 【月来better】
const arr = [1, 2, 3, 4, 5];
let ranArr = [];
const randomchoice = function factory(arr) {
let rnd = Math.floor(Math.random() * arr.length);
if (ranArr.includes(rnd)) return factory(arr);
ranArr.push(rnd);
return arr[rnd];
};
console.log(randomchoice(arr));
console.log(randomchoice(arr));
console.log(randomchoice(arr));
console.log(randomchoice(arr));
console.log(randomchoice(arr));

边栏推荐
- Implementation of six singleton modes
- 二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
- TIPC介绍1
- TIPC Cluster5
- Is the account above changtou school safe?
- Uncover the secrets of Huawei application market application statistics
- PKG package manager usage instance in FreeBSD
- [AGC] build service 3 - authentication service example
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- Huawei game failed to initialize init with error code 907135000
猜你喜欢

flink二開,實現了個 batch lookup join(附源碼)

Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)

Uncover the secrets of Huawei application market application statistics
![[applinking practical case] share in app pictures through applinking](/img/12/5616f1fa55387b81e25e55a98022b9.png)
[applinking practical case] share in app pictures through applinking

三.芯片啟動和時鐘系統

Use of vscode tool

【AI应用】海康威视iVMS-4200软件安装

TIPC Cluster5

Matlab processing of distance measurement of experimental electron microscope

V2X-Sim数据集(上海交大&纽约大学)
随机推荐
Luogu p1892 [boi2003] Gang (and search for variant anti set)
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
Verilog and VHDL signed and unsigned number correlation operations
Primary key policy problem
一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)
OpenMLDB Meetup No.4 会议纪要
One trick to quickly realize custom application titlebar
华为应用市场应用统计数据问题大揭秘
Resources读取2d纹理 转换为png格式
在网上开股票账户安全吗?我是新手,还请指导
[ark UI] implementation of the startup page of harmonios ETS
二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
TIPC Service and Topology Tracking4
TIPC Getting Started6
The working day of the month is calculated from the 1st day of each month
Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
[in simple terms, play with FPGA learning 3 ----- basic grammar]
Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)
二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
Static variables in static function