autocomplete-bullshit

Benchmark created by Flip on


Test runner

Ready to run.

Testing in
TestOps/sec
readable
function autocomplete(input, dictionary) {
  var count = 1;
  return dictionary.filter(function(word, index) {
    var preparedInput = input.toLowerCase().replace(/[^a-z]/g, '');
    var substring = word.toLowerCase().replace(/[^a-z]/g, '').substring(0, preparedInput.length);
    return substring === preparedInput && count <= 5 ? count++ : false;
  });
}

autocomplete('ca5t', ['Catastrophe', 'Ca5-*&$^--425%%%%tastrophe', '', 'lol', 'no', 'cattt', 'cat', 'cat', 'cat', 'cat', 'CAP', 'catch']);
ready
shit
function autocomplete(input, dictionary) {
  var r = new RegExp('^' + input.replace(/[^a-z]/gi, ''), 'i');
  return dictionary.filter(function(w) {
    return r.test(w);
  }).slice(0, 5);
}

autocomplete('ca5t', ['Catastrophe', 'Ca5-*&$^--425%%%%tastrophe', '', 'lol', 'no', 'cattt', 'cat', 'cat', 'cat', 'cat', 'CAP', 'catch']);
ready

Revisions

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