Character exists in set

Benchmark created on


Description

This checks different methods for seeing if every character in a given string exists in an allowed list of characters.

Setup

const BASE36_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

const test = "IEKT104IWO40VL13K";

Test runner

Ready to run.

Testing in
TestOps/sec
Iterate over charcters
  for (const ch of test) {
    if (!BASE36_ALPHABET.includes(ch)) {
      return false;
    }
  }
  return true;
ready
Use set+array functions
  const allowedCharSet = new Set(BASE36_ALPHABET);
  return Array.from(test).every(c => allowedCharSet.has(c));
ready
Use set functions
  const allowedCharSet = new Set(BASE36_ALPHABET);
  return (new Set(test)).isSubsetOf(allowedCharSet);
ready
Usa arrays
return Array.from(test).every(c=> BASE36_ALPHABET.includes(c));
ready
Use regex
const t = new RegExp(`^[${BASE36_ALPHABET}]+$`)
return t.test(test);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.