bitty installation snippets examples documentation q&a

snippets

shuffle an array

  • The b.shuffle() method provides a basic shuffling of an array of strings.

html

<div data-r="items"></div>
<button data-s="shuffle">Shuffle</button>

javascript

export const b = { init: "items" };

const theItems = ["alfa", "bravo", "charlie", "delta", "echo", "foxtrot"];

export function items(_, __, el) {
  el.innerHTML = theItems.join(" - ");
}

export function shuffle(_, __, ___) {
  b.shuffle(theItems);
  b.trigger("items");
}