Created
September 6, 2019 17:32
-
-
Save mixdev/3c47781df5e528ca104b4c92b63895c7 to your computer and use it in GitHub Desktop.
A reusable rank normalizer. Should use with map. (Reminder. you may use a normal loop counter if you have just one place to use this)
This file contains hidden or 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
class rankNormalizer{ | |
static normalize(){ | |
rankNormalizer.count = typeof rankNormalizer.count !== 'undefined'?++rankNormalizer.count:1 | |
//console.log(rankNormalizer.count); | |
return rankNormalizer.count; | |
}; | |
static reset(){ | |
rankNormalizer.count=null | |
} | |
} | |
rankNormalizer.normalize();// 1 | |
rankNormalizer.normalize();// 2 | |
rankNormalizer.normalize();// 3 | |
rankNormalizer.reset(); | |
rankNormalizer.normalize();// 1 | |
rankNormalizer.normalize();// 2 | |
rankNormalizer.normalize();// 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
However, you can do this in oneshot if you use sort() & keys() on an array. If it is an object array, use Lodash but use the same technique
x=[{ 'a': 1, 'b': 2 , c:3, d:4, e:5},{ 'a': 2, 'b': 3 , c:3, d:4, e:5},{ 'a': 6, 'b': 3 , c:3, d:4, e:5}] y=_.keys(x);//it is array of strings: you may need to typecast in some cases.