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

边栏推荐
- Creation and use of unified links in Huawei applinking
- [play with FPGA learning 2 in simple terms ----- design skills (basic grammar)]
- String (Analog
- 【深入浅出玩转FPGA学习3-----基本语法】
- ros缺少catkin_pkg
- Summary of cases of players' disconnection and reconnection in Huawei online battle service
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- 从攻击面视角,看信创零信任方案实践
- Verilog and VHDL signed and unsigned number correlation operations
- Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
猜你喜欢

OpenMLDB Meetup No.4 会议纪要
![[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](/img/5c/b0030fd5fbc07eb94013f2699c2a04.png)
[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

二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)

华为AppLinking中统一链接的创建和使用

webauthn——官方开发文档

Multi line display and single line display of tqdm

JVM之垃圾回收器

enumrate的start属性的坑

flink二開,實現了個 batch lookup join(附源碼)

How does the whole network display IP ownership?
随机推荐
高德根据轨迹画线
二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
One trick to quickly realize custom application titlebar
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
二叉树专题--AcWing 1589. 构建二叉搜索树
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
OpenMLDB Meetup No.4 会议纪要
TIPC协议
Complement (Mathematical Simulation
JVM之垃圾回收器
[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
Uncover the secrets of Huawei application market application statistics
static 函数中的静态变量
php中self和static在方法中的区别
TIPC Cluster5
Appgallery connect scenario development practice - image storage and sharing
Pit of the start attribute of enumrate
How to transfer event objects and user-defined parameters simultaneously in Huawei express applications
ros gazebo相关包的安装