相关疑难解决方法(0)

如何随机化(shuffle)一个JavaScript数组?

我有这样一个数组:

var arr1 = ["a", "b", "c", "d"];
Run Code Online (Sandbox Code Playgroud)

我如何随机化/随机播放?

javascript arrays shuffle

1138
推荐指数
36
解决办法
67万
查看次数

Array.sort()方法在不同浏览器中的稳定性是什么?

我知道ECMA脚本规范没有指定用于排序数组的算法,也没有指定排序是否应该是稳定的.

我在Firefox中找到了这个信息,它指明firefox使用稳定的排序.

有谁知道IE 6/7/8,Chrome和Safari?

javascript arrays sorting cross-browser stable-sort

63
推荐指数
3
解决办法
2万
查看次数

随机orderBy在AngularJS 1.2中返回'infdig'错误

orderBy这个问题中使用随机排序技术在AngularJS 1.1中运行良好.

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.list = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
    $scope.random = function() {
        return 0.5 - Math.random();
    }
}
Run Code Online (Sandbox Code Playgroud)

但是在1.2中,它会将infdig错误放入控制台并花费更长的时间来返回排序结果:http: //jsfiddle.net/mblase75/jVs27/

控制台中的错误如下所示:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: $watchCollectionWatch; newVal: 42; oldVal: 36"],["fn: $watchCollectionWatch; newVal: 47; oldVal: 42"],["fn: $watchCollectionWatch; newVal: 54; oldVal: 47"],["fn: $watchCollectionWatch; newVal: 61; oldVal: 54"],["fn: $watchCollectionWatch; newVal: 68; oldVal: 61"]]
Run Code Online (Sandbox Code Playgroud)

该文档orderBy …

javascript angularjs angularjs-orderby

5
推荐指数
1
解决办法
3641
查看次数