Simple React Typeahead & Faster Array Filter

Here is a super simple yet nicely working React typeahead I created couple of days ago after pretty much not being able to find any bug free & lightweight typeahead for React.

It’s weird because while there are too many Typeahead[s] for AngularJS, while I guess React is still in the awkward teenage phase.

Also, I ended up creating a custom Array filter, because well, it is evidently much faster than the native Array.prototype.filter().

The faster Array filter can be defined as:

Array.prototype.where = Array.prototype.where || function(t) {
  var results = [];

  for(var i = 0, len = this.length; i < len; i++) {
    var item = this[i];

    if (t(item)) {

  return results;

Although I don’t think there is going to be any noticeable difference unless the size of array is quite large.

Function Maps in JavaScript

var map = {
  functionOne: function(obj) {
    return'I am at functionOne: %o', obj);
  functionTwo: function(obj) {
    return'I am at functionTwo: %o', obj);
  functionThree: function(obj) {
    return'I am at functionThree: %o', obj);

C like function map which can then be used like map.functionOne({foo: 'bar'}).

I prefer to use objects like these instead of more typical control flow statements like if/else or switch. The map object can be called like map[key]({hello: 'World'}) , where key is the string.

Suppose you’re getting a data array of objects from some request, I can very neatly check all the items using something like this:

var arr ={
    return item[map[key](item)];