Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shuffle #20

Open
chiyan-lin opened this issue Oct 11, 2020 · 0 comments
Open

shuffle #20

chiyan-lin opened this issue Oct 11, 2020 · 0 comments

Comments

@chiyan-lin
Copy link
Owner

// 快速洗牌

var shuffle = (array) => {
  let m = array.length
  while (m) {
    const i = Math.floor(Math.random() * m--)
    [array[m], array[i]] = [array[i], array[m]]
  }
  return array
}
console.log('[1, 2, 3, 4, 5]', shuffle([1, 2, 3, 4, 5]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant