Created
April 11, 2016 18:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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