wombats-writing-code / fbw-components

Fly-by-Wire components for building user interfaces
http://fbw.mit.edu
MIT License
0 stars 1 forks source link

better search for outcomes #39

Open luwen-huang opened 7 years ago

luwen-huang commented 7 years ago

can we have the dropdown search for outcomes search by not-necessarily contiguous words? only if it's a quick patch.

something like this (from https://github.com/wombats-writing-code/fbw-instructor/blob/master/web/src/reducers/utilities.js#L4):

export const matches = (needle, haystack) => {
  let parts = needle.split(' ');
  let partQ = '';
  for (let i=0; i<parts.length; i++) {
    if (i==0) {
      partQ = '(?=.*\\b' + parts[i] + ')';
    } else {
      partQ = partQ + '(?=.*\\b' +  parts[i] + ')';
    }
  }

  let re = new RegExp(partQ, 'gi');
  let matching = re.test(haystack);

  return matching;
}