Skip to content

Instantly share code, notes, and snippets.

@eranbetzalel
Last active March 7, 2016 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eranbetzalel/9f16b1216931e20775ad to your computer and use it in GitHub Desktop.
Save eranbetzalel/9f16b1216931e20775ad to your computer and use it in GitHub Desktop.
Implementation of the n-gram algorithm using JavaScript
function ngrams(array, length) {
var ngramsArray = [];
for (var i = 0; i < array.length - (length - 1); i++) {
var subNgramsArray = [];
for (var j = 0; j < length; j++) {
subNgramsArray.push(array[i + j])
}
ngramsArray.push(subNgramsArray);
}
return ngramsArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment