I have a simple function that I ran through Google's Closure Compiler Service:
var fisherYatesShuffle = function(array) {
var currentIndex = array.length;
var temporaryValue;
var randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
};
It gave me back the following (which I've pretty-printed):
var fisherYatesShuffle = function(a) {
for (var b = a.length, d, c; 0 !== b;) c = Math.floor(Math.random() * b), --
b, d = a[b], a[b] = a[c], a[c] = d;
return a
};
What is this 'dash dash' rass at the end of line two? Why have I never seen it?
答案 0 :(得分:4)
它是--
b
--b
预先递减运算符。
与
相同b = b - 1;
它在下一行拆分,因为该行已有80个字符(最大值)。