Minor fixes. (#91)

* Get Bit: Make more terse

* Power of two: Allowed 1 as a valid power of 2.
Power of two: Removed unnecessary exception throwing.

* Fisher Yates: Made more terse

* Least Common Multiple: Fill undefined value

* Greatest Common Divisor: Fill undefined value.
Greatest Common Divisor: Make more terse.
This commit is contained in:
Bruce-Feldman
2018-07-04 10:53:22 -04:00
committed by Oleksii Trekhleb
parent 93bfe97e27
commit e36c441fa9
10 changed files with 15 additions and 75 deletions

View File

@@ -6,15 +6,9 @@ export default function fisherYates(originalArray) {
// Clone array from preventing original array from modification (for testing purpose).
const array = originalArray.slice(0);
if (array.length <= 1) {
return array;
}
for (let i = (array.length - 1); i > 0; i -= 1) {
const randomIndex = Math.floor(Math.random() * (i + 1));
const tmp = array[randomIndex];
array[randomIndex] = array[i];
array[i] = tmp;
[array[i], array[randomIndex]] = [array[randomIndex], array[i]];
}
return array;