coffeescript-cookbook / coffeescript-cookbook.github.io

CoffeeScript Recipes, Examples and Tutorials
https://coffeescript-cookbook.github.io
Other
562 stars 178 forks source link

fixed broken shuffle for arrays of length 1 or 0 #126

Closed malgorithms closed 9 years ago

malgorithms commented 9 years ago

Coffeescript's range evaluator (in this case [a.length-1..1]) produces inappropriate results for Fisher-Yates when the array is length 1 or 0. The unfixed shuffle pushes undefined values onto the the array. A length check is necessary to continue with this style.