当前位置:网站首页>JS -- take a number randomly from the array every call, and it cannot be the same as the last time
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
2022-07-02 11:17:00 【Month 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));

边栏推荐
- Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
- Internship report skywalking distributed link tracking?
- PHP tea sales and shopping online store
- 数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
- 通过券商经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
- tqdm的多行显示与单行显示
- V2x SIM dataset (Shanghai Jiaotong University & New York University)
- 三.芯片啟動和時鐘系統
- The working day of the month is calculated from the 1st day of each month
- Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)
猜你喜欢
![[play with FPGA learning 5 in simple terms ----- reset design]](/img/57/816a59787259dc32b52897c069e1a6.png)
[play with FPGA learning 5 in simple terms ----- reset design]

Pit of the start attribute of enumrate

VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题

ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘

Matlab processing of distance measurement of experimental electron microscope

Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)

One trick to quickly realize custom application titlebar

The most detailed MySQL installation tutorial

Skills of PLC recorder in quickly monitoring multiple PLC bits

Special topic of binary tree -- acwing 1589 Building binary search tree
随机推荐
What are the methods of adding elements to arrays in JS
Calculate the sum of sequences
Native method merge word
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
mmrotate旋转目标检测框架使用记录
在网上开股票账户安全吗?我是新手,还请指导
What are the software product management systems? Inventory of 12 best product management tools
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
Xiao Sha's pain (double pointer
How does the whole network display IP ownership?
Jenkins安装
The difference between self and static in PHP in methods
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
Flick two open, realized a batch lookup join (with source code)
TIPC协议
Array splitting (regular thinking
Flink two Open, implement Batch Lookup join (attached source)
OpenMLDB Meetup No.4 会议纪要
TIPC protocol
TIPC Getting Started6