lodash#sampleSize TypeScript Examples

The following examples show how to use lodash#sampleSize. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleQueries.tsx    From hub with Apache License 2.0 6 votes vote down vote up
SampleQueries = (props: Props) => {
  const sampleQueries: SampleQuery[] = getSampleQueries();
  if (sampleQueries.length === 0) {
    return null;
  }
  const queries = sampleQueries.length > QUERIES_NUMBER ? sampleSize(sampleQueries, QUERIES_NUMBER) : sampleQueries;

  return (
    <>
      {queries.map((query: SampleQuery, index: number) => (
        <Fragment key={`sampleQuery_${index}`}>
          <Link
            className={`badge rounded-pill border fw-normal mx-2 mt-3 ${props.className}`}
            to={{
              pathname: '/packages/search',
              search: `?${query.queryString}`,
            }}
            aria-label={`Filter by ${query.name}`}
          >
            {query.name}
          </Link>
          {!isUndefined(props.lineBreakIn) && index === props.lineBreakIn - 1 && (
            <div className="d-block w-100" data-testid="sampleQueryBreakLine" />
          )}
        </Fragment>
      ))}
    </>
  );
}
Example #2
Source File: detector.ts    From querybook with Apache License 2.0 6 votes vote down vote up
export function detectTypeForValues<T>(
    values: T[],
    detector: (value: T) => boolean
): boolean {
    const sizeOfSample = Math.max(
        DETECTOR_MIN_SAMPLE_SIZE,
        Math.floor(values.length / 100)
    );
    const sampleValues = sampleSize(values, sizeOfSample);
    return sampleValues.every(detector);
}
Example #3
Source File: collection.ts    From aqualink-app with MIT License 5 votes vote down vote up
createCollection = (sites: Site[], nSites: number): Collection => {
  const sample = sampleSize(sites, nSites);

  return {
    name: "My dashboard",
    sites: sample,
  };
}
Example #4
Source File: demo.ts    From slippi-stats with MIT License 5 votes vote down vote up
export function generateDemoValues(): Record<string, any> {
  const paramMap: Record<string, any> = {};

  // Set names
  paramMap.name1 = "FOLLOW";
  paramMap.name2 = "ON";
  paramMap.sub1 = "@_vinceau";
  paramMap.sub2 = "TWITTER";

  // Set colors
  const [char1, color1] = generateRandomCharacter();
  const [char2, color2] = generateRandomCharacter();
  paramMap.char1 = char1;
  paramMap.color1 = color1;
  paramMap.char2 = char2;
  paramMap.color2 = color2;

  // Random games
  const totalGames = getRandomInt(3, 5);
  paramMap.gt = totalGames;
  sampleSize(LEGAL_STAGE_IDS, totalGames).forEach((stage, i) => {
    const gameKey = `g${i + 1}`;
    const leftWillWin = Math.random() < 0.5;
    const leftPlayerInfo = [char1, color1, leftWillWin ? "winner" : "loser"].join(",");
    const rightPlayerInfo = [char2, color2, leftWillWin ? "loser" : "winner"].join(",");
    const gameValue = generateRandomGame([leftPlayerInfo, rightPlayerInfo], stage);
    paramMap[gameKey] = gameValue;
  });

  const demoStats = [
    Stat.KILL_MOVES,
    Stat.NEUTRAL_OPENER_MOVES,
    "",
    Stat.OPENINGS_PER_KILL,
    Stat.DAMAGE_DONE,
    Stat.AVG_KILL_PERCENT,
    Stat.NEUTRAL_WINS,
  ];

  paramMap.stats = demoStats.join(",");

  demoStats
    .filter((s) => Boolean(s))
    .forEach((statId) => {
      [1, 2].forEach((player) => {
        const key = statId + player;
        paramMap[key] = generateRandomStat(statId);
      });
    });
  return paramMap;
}