Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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