Skip to content
Snippets Groups Projects
Select Git revision
  • 89965bdcf2eeb99c9c66040808d410b19ec0d8e3
  • main default protected
  • renovate/main-ghcr.io-renovatebot-base-image-11.x
  • renovate/main-vitest-eslint-plugin-1.x
  • renovate/main-actions-setup-node-5.x
  • jamietanna-patch-2
  • jamietanna-patch-1
  • test/mc-maven
  • feat/minimumReleaseAgeTimestamp-required
  • defect/test-name
  • renovate/main-linters
  • renovate/main-find-up-8.x
  • refactor/pin-new-value
  • fix/user-agent
  • feat/37517-base64-private-key
  • next
  • feat/gnupg
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • 41.144.1
  • 41.144.0
  • 41.143.3
  • 41.143.2
  • 41.143.1
  • 41.143.0
  • 41.142.1
  • 41.142.0
  • 41.141.0
  • 41.140.3
  • 41.140.2
  • 41.140.1
  • 41.140.0
  • 41.139.1
  • 41.139.0
  • 41.138.5
  • 41.138.4
  • 41.138.3
  • 41.138.2
  • 41.138.1
41 results

index.ts

Blame
  • user avatar
    Rhys Arkins authored and GitHub committed
    Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>
    bf093370
    History
    index.ts 522 B
    export function sampleSize(array: string[], n: number): string[] {
      const length = array ? array.length : 0;
      if (!length || n < 1) {
        return [];
      }
    
      const sampleNumber = n > length ? length : n;
      let index = 0;
      const lastIndex = length - 1;
      const result = [...array];
      while (index < sampleNumber) {
        const rand = index + Math.floor(Math.random() * (lastIndex - index + 1));
        [result[rand], result[index]] = [result[index], result[rand]];
        index += 1;
      }
      return result.slice(0, sampleNumber);
    }