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

边栏推荐
- 【云原生】2.5 Kubernetes 核心实战(下)
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- PowerBI中导出数据方法汇总
- Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
- How to use ide to automatically sign and debug Hongmeng application
- V2x SIM dataset (Shanghai Jiaotong University & New York University)
- TIPC介绍1
- TIPC 寻址2
- Special topic of binary tree -- [deep base 16. Example 7] ordinary binary tree (simplified version) (multiset seeks the precursor and subsequent sentry Art)
- Flick two open, realized a batch lookup join (with source code)
猜你喜欢

【IDEA】使用插件一键逆向生成代码

一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)

JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个

【深入浅出玩转FPGA学习2----设计技巧(基本语法)】

TIPC Service and Topology Tracking4

flink二开,实现了个 batch lookup join(附源码)

Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)

Creation and use of unified links in Huawei applinking

三.芯片啟動和時鐘系統

What are the software product management systems? Inventory of 12 best product management tools
随机推荐
Rest (XOR) position and thinking
Jenkins installation
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)
SQLite modify column type
Use Huawei performance management service to configure the sampling rate on demand
Multi line display and single line display of tqdm
Some suggestions for young people who are about to enter the workplace in the graduation season
Jenkins安装
Implementation of six singleton modes
Static variables in static function
Flink two Open, implement Batch Lookup join (attached source)
PLC-Recorder快速监控多个PLC位的技巧
【深入浅出玩转FPGA学习2----设计技巧(基本语法)】
Functional interfaces and method references
启牛商学院给的股票账户安全吗?能开户吗?
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
JVM garbage collector
Thanos Receiver