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

边栏推荐
- PHP tea sales and shopping online store
- 二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
- What are the software product management systems? Inventory of 12 best product management tools
- [in simple terms, play with FPGA learning 3 ----- basic grammar]
- MTK full dump抓取
- Implementation of six singleton modes
- 每月1号开始计算当月工作日
- static 函数中的静态变量
- Iii. Système de démarrage et d'horloge à puce
- Supermarket (heap overload
猜你喜欢

QT learning diary 8 - resource file addition

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

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)

Importerror: impossible d'importer le nom « graph» de « graphviz»

洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)

V2x SIM dataset (Shanghai Jiaotong University & New York University)

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

Why does LabVIEW lose precision in floating point numbers

TIPC Cluster5

二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
随机推荐
TIPC Cluster5
[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched
flink二开,实现了个 batch lookup join(附源码)
二叉树专题--AcWing 1589. 构建二叉搜索树
金山云——2023届暑期实习
V2X-Sim数据集(上海交大&纽约大学)
OpenMLDB Meetup No.4 会议纪要
Flick two open, realized a batch lookup join (with source code)
TIPC Getting Started6
二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)
ros gazebo相关包的安装
QT学习日记8——资源文件添加
mmrotate旋转目标检测框架使用记录
V2x SIM dataset (Shanghai Jiaotong University & New York University)
QT learning diary 7 - qmainwindow
ros缺少catkin_pkg
String (Analog
高德根据轨迹画线
Uncover the secrets of Huawei application market application statistics
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘