X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Futils%2Falea.js;h=9ff11593586a0a099d64f95ba919a91dfb4236ec;hp=04563938ce091bd789c7d89dfd550bdda1594141;hb=6808d7a16ec1e761c6a2dffec2281c96953e4d89;hpb=ae2c49bb0bbaac3953f63be5b720e9c6835f00b6 diff --git a/client/src/utils/alea.js b/client/src/utils/alea.js index 04563938..9ff11593 100644 --- a/client/src/utils/alea.js +++ b/client/src/utils/alea.js @@ -1,27 +1,26 @@ // Random (enough) string for socket and game IDs -export function getRandString() -{ - return (Date.now().toString(36) + Math.random().toString(36).substr(2, 7)) - .toUpperCase(); +export function getRandString() { + return ( + Date.now().toString(36) + + Math.random() + .toString(36) + .substr(2, 7) + ).toUpperCase(); } -export function randInt(min, max) -{ - if (!max) - { +export function randInt(min, max) { + if (!max) { max = min; min = 0; } - return Math.floor(Math.random() * (max - min) ) + min; + return Math.floor(Math.random() * (max - min)) + min; } // Inspired by https://github.com/jashkenas/underscore/blob/master/underscore.js -export function sample (arr, n) -{ +export function sample(arr, n) { n = n || 1; let cpArr = arr.map(e => e); - for (let index = 0; index < n; index++) - { + for (let index = 0; index < n; index++) { const rand = randInt(index, arr.length); const temp = cpArr[index]; cpArr[index] = cpArr[rand]; @@ -30,7 +29,6 @@ export function sample (arr, n) return cpArr.slice(0, n); } -export function shuffle(arr) -{ +export function shuffle(arr) { return sample(arr, arr.length); }