当前位置:网站首页>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));

边栏推荐
- js中给数组添加元素的方法有哪些
- JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
- III Chip startup and clock system
- From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
- Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)
- 每月1号开始计算当月工作日
- 一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)
- 在网上开股票账户安全吗?我是新手,还请指导
- Regular and common formulas
- [paid promotion] collection of frequently asked questions, recommended list FAQ
猜你喜欢
随机推荐
V2x SIM dataset (Shanghai Jiaotong University & New York University)
What are the software product management systems? Inventory of 12 best product management tools
Is bond fund safe? Does the bond buying foundation lose principal?
JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
ros gazebo相关包的安装
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
spritejs
JVM garbage collector
Verilog and VHDL signed and unsigned number correlation operations
TIPC Cluster5
[paid promotion] collection of frequently asked questions, recommended list FAQ
Creation and use of unified links in Huawei applinking
[quick application] win7 system cannot run and debug projects using Huawei ide
一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)
函数式接口和方法引用
Skills of PLC recorder in quickly monitoring multiple PLC bits
Complement (Mathematical Simulation
flink二开,实现了个 batch lookup join(附源码)
Regular and common formulas
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)




![[in simple terms, play with FPGA learning 3 ----- basic grammar]](/img/f0/0204fa5197033877dc0758203253ae.png)



