How to use unique-random-array - 2 common examples

To help you get started, we’ve selected a few unique-random-array examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kentcdodds / starwars-names / src / index.js View on Github external
import uniqueRandomArray from 'unique-random-array';
import starWarsNames from './starwars-names.json';

const getRandomItem = uniqueRandomArray(starWarsNames);

module.exports = {
  all: starWarsNames,
  random: random
};

function random(number) {
  if (number === undefined) {
    return getRandomItem();
  } else {
    const randomItems = [];
    for (let i = 0; i < number; i++) {
      randomItems.push(getRandomItem());
    }
    return randomItems;
  }
github tsevdos / greek-in-tech / src / index.js View on Github external
import uniqueRandomArray from "unique-random-array";
import entries from "../data/entries";

export const all = entries;
export const random = uniqueRandomArray(entries);
export const getEntry = (id = 1) => {
  const entry = entries[id - 1];
  if (!entry) {
    throw new Error("Invalid ID");
  }

  return entry;
};

unique-random-array

Get consecutively unique elements from an array

MIT
Latest version published 7 months ago

Package Health Score

64 / 100
Full package analysis

Popular unique-random-array functions