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

边栏推荐
- ctf 记录
- Regular and common formulas
- How does the whole network display IP ownership?
- Uncover the secrets of Huawei application market application statistics
- Appgallery connect scenario development practice - image storage and sharing
- Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
- TIPC addressing 2
- Pit of the start attribute of enumrate
- 一招快速实现自定义快应用titlebar
- 启牛商学院给的股票账户安全吗?能开户吗?
猜你喜欢

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

QT学习日记8——资源文件添加

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

华为快应用中如何实现同时传递事件对象和自定义参数

Verilog and VHDL signed and unsigned number correlation operations
![[in simple terms, play with FPGA learning 3 ----- basic grammar]](/img/f0/0204fa5197033877dc0758203253ae.png)
[in simple terms, play with FPGA learning 3 ----- basic grammar]

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

MTK full dump抓取

金山云——2023届暑期实习

The first white paper on agile practice in Chinese enterprises was released | complete download is attached
随机推荐
The difference between self and static in PHP in methods
Rest (XOR) position and thinking
【AI应用】海康威视iVMS-4200软件安装
TIPC Service and Topology Tracking4
[play with FPGA learning 5 in simple terms ----- reset design]
[paid promotion] collection of frequently asked questions, recommended list FAQ
每月1号开始计算当月工作日
Approximate sum count (approximate
Gaode draws lines according to the track
Creation and use of unified links in Huawei applinking
从攻击面视角,看信创零信任方案实践
The working day of the month is calculated from the 1st day of each month
如何用list组件实现tabbar标题栏
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
二叉树专题--【深基16.例7】普通二叉树(简化版)(multiset 求前驱 后继 哨兵法)
Implement custom drawer component in quick application
[ark UI] implementation of the startup page of harmonios ETS
TIPC addressing 2
ros gazebo相关包的安装
Openmldb meetup No.4 meeting minutes