forked from hola/challenge_word_classifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.js
3 lines (3 loc) · 3.67 KB
/
solution.js
1
2
3
var bloom={h0:function(a){for(var b=1,c=0;c<a.length;++c){var d=a.charCodeAt(c)-95;0>d&&(d=0);b=133*b+d&1048575}return b},test:function(a,b){var c=this.h0(b)%524287;return 0!=(a[2197+Math.floor(c/8)]&1<<c%8)}},gw1="a'asia baha'i baha'i's baha'ullah baha'ullah's bahc'ae cap'n ch'an ch'in ch'in's ch'ing cha'ah d'aeth d'amboise d'amour d'andre d'annunzio d'arcy d'arcy's d'arrest d'artagnan d'attoma d'avenant d'iberville d'ignazio d'inzeo d'oria d'urfey d'arcy d'ewart der'a gi'd gi'ing ge'ez hallowe'en i'd i'll i'm i've ko'd ko'ing kinko's's l'allegro l'amour l'amour's l'aquila l'avare l'enfant l'etranger l'hospital l'immoraliste l'oreal l'oreal's l'otage l'ouverture l'ouverture's l'vov landsm'al levi's's m'ba m'taggart m'sieur mcdonald's's mu'min n'djamena n'djamena ne'erday nuku'alofa o'boyle o'brien o'brien's o'callaghan o'callaghan's o'carroll o'carroll's o'casey o'casey's o'connell o'connell's o'conner o'conner's o'connor o'connor's o'dell o'dell's o'doneven o'doneven's o'donnell o'donnell's o'donoghue o'donoghue's o'donovan o'donovan's o'driscoll o'driscoll's o'dwyer o'fallon o'faolain o'faolcin o'fiaich o'flaherty o'gowan o'gowan's o'grady o'grady's o'hara o'hara's o'hare o'higgins o'higgins's o'keeffe o'keeffe's o'kelley o'kelly o'kelly's o'leary o'mahony o'mahony's o'malley o'malley's o'meara o'meara's o'neil o'neil's o'neill o'neill's o'reilly o'reilly's o'rourke o'rourke's o'shea o'shee o'shee's o'sullivan o'toole o'toole's ok'd ok'ing po'd prud'hon qur'an qur'anic san'a shari'a shari'a's shi'ite shi'ite's t'ang t'ang's to'd ta'izz wendy's's xi'an xi'an's zu'lkadah a'body a'thing ain't akwa'ala all'antica all'italiana all'ottava amn't an'a an't anybody'd ar'n't aren't b'hoy baws'nt betra'ying bo's'n bo's'n's bo's'ns bo'sun bo'sun's bo'suns bos'n bos'n's bos'ns br'er ca'canny can't ch'in could've couldn't cowslip'd d'albert d'alembert d'arblay d'arezzo d'arezzo's d'estaing d'estaing's d'holbach d'indy d'accord d'art d'etat d'oeuvre daren't dasn't dassn't didn't doctors'commons doesn't dog'sbane don't don'ts e'en e'er entr'acte entr'acte's entr'actes fa'ard fatwa'd fo'c's'le fo'c's'le's fo'c's'les fo'c'sle fo'c'sle's fo'c'sles freez'd g'day guv'nor guv'nor's guv'nors h'm ha'it ha'nt ha'p'orth ha'p'orth's ha'p'orths ha'pennies ha'penny ha'penny's ha'pennyworth hadn't hain't hallowe'en halo'd han't hasn't haven't he'd he'll her'n his'n how'd how're howe'er i'd i'faith i'll i'm i've idea'd in't isn't it'd it'll j'accuse j'adoube j'ouvert jews'harp jusqu'auboutisme jusqu'auboutist jusqu'auboutiste k'ri ko'd l'addition l'aquila l'chaim l'envoy l'oeil l'tre los'te ma'am mayn't might've mightn't mu'adhdhin must've mustn't n'djamena n'gana n'importe n't nasta'liq ne'er needn't nobody'd nor'east nor'easter nor'west nor'wester north'ard o'clock o'er o'ertop ogee'd oughtn't our'n pa'anga penn'orth penn'orth's penn'orths po'chaise pyjama'd qur'an rec'd s'elp s'help samh'in schoolma'am se'nnight sec'y sha'ban shan't she'd she'll she'ol shi'ite should've".split(" "),
bw2char="jq jx jz qj qx qz vq xj zx".split(" "),byteBuf;module.exports={init:function(a){byteBuf=Buffer.from(a,"binary")},test:function(a){a=a.toLowerCase();if(this.U(a))return!1;if(0<=a.indexOf("'")){if(0<=gw1.indexOf(a))return!0;"'s"==a.substr(-2)&&(a=a.substr(0,a.length-2));if(0<=a.indexOf("'"))return!1}return 18>a.length&&10>Math.abs(a.length-(a.match(/[euioa']/g)||[]).length)&&Y(a)&&bloom.test(byteBuf,a)?!0:!1},U:function(a){for(var b in bw2char)if(0<=a.indexOf(bw2char[b]))return!0;return!1}};
function W(a){return 676*(a.charCodeAt(0)-97)+26*(a.charCodeAt(1)-97)+(a.charCodeAt(2)-97)}function X(a,b){return a[Math.floor(b/8)]&1<<b%8}function Y(a){for(var b=0;b<a.length-2;b++)if(0==X(byteBuf,W(a.substr(b,3))))return!1;return!0};