Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Created April 11, 2016 18:21
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 primaryobjects/377989f60dfccc575aab70ed8a762fb9 to your computer and use it in GitHub Desktop.
Save primaryobjects/377989f60dfccc575aab70ed8a762fb9 to your computer and use it in GitHub Desktop.
Method for converting a natural language ordinal to a numerical value. Given an array, first = 1, second = 2, last = arr.length
CommonManager = {
wordToNumber: function(word, arr) {
var dict = {
'first': 1,
'second': 2,
'third': 3,
'fourth': 4,
'fifth': 5,
'sixth': 6,
'seventh': 7,
'eighth': 8,
'ninth': 9,
'tenth': 10,
'last': arr ? arr.length : null,
'1st': 1,
'2nd': 2,
'3rd': 3,
'4th': 4,
'5th': 5,
'6th': 6,
'7th': 7,
'8th': 8,
'9th': 9,
'10th': 10
};
return word ? dict[word.toLowerCase()] : null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment