Skip to content
HangoverHangover
首页
项目收藏
留言板
github icon
  • 代码片段

      • 数组合并
        • 最大/最小值
          • Set 对象作用
            • 过滤虚假值
              • 数组洗牌
                • 删除重复元素
                  • 数组比较

                数组洗牌

                author iconHangovercalendar icon2022年4月15日category icon
                • 数组
                tag icon
                • 随机
                • 洗牌
                • 算法
                timer icon小于 1 分钟

                数组随机洗牌算法

                const shuffle = (arr) => {
                    var result = [],
                        random;
                    while (arr.length > 0) {
                        random = Math.floor(Math.random() * arr.length);
                        result.push(arr[random])
                        arr.splice(random, 1)
                    }
                    return result;
                }
                
                1
                2
                3
                4
                5
                6
                7
                8
                9
                10
                上一页
                过滤虚假值
                下一页
                删除重复元素
                鸟无声兮山寂寂,夜正长兮风淅淅。 ──李华《吊古战场文》
                Copyright © 2023 Hangover