Random but just in Chrome

后端 未结 3 407
轮回少年
轮回少年 2021-01-22 09:33

I\'ve this function to create a random range of numbers.

function randomRange(min, max) {
  return (new Array(++max-min))
  .join(\'.\').split(\'.\')
  .map(func         


        
3条回答
  •  遇见更好的自我
    2021-01-22 10:16

    According to MDN,

    array.sort([compareFunction])

    If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, but sorted with respect to all different elements. Note: the ECMAscript standard does not guarantee this behaviour, and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.

    You can try

    .sort(function(){ return Math.random()*2-1; })
    

    All you're trying to do here is to return a number that is either greater, less than or equal to 0.

提交回复
热议问题