Skip to content

Instantly share code, notes, and snippets.

View chrisdc's full-sized avatar

Christopher Crouch chrisdc

View GitHub Profile
@chrisdc
chrisdc / stemmer.js
Last active October 8, 2018 12:35
A compact implementation of the Porter 2 stemming algorithm in Javascript
'use strict';
function handleSuffix(word, patterns) {
var wordLen = word.length;
for (var i = 0, len = patterns.length; i < len; i++) {
if (patterns[i][0].test(word)) {
if (wordLen - patterns[i][3] < patterns[i][2]) {
// The given suffix does not fit in the required region.
return word;
@chrisdc
chrisdc / search.js
Last active October 11, 2018 10:05
Binary Search
function search(key, data) {
var min = 0;
var max = data.length - 1;
var half;
while (max >= min) {
half = Math.floor((max + min)/2);
if (data[half] === key) {
return half;