I am looking for the best possible, minimum operation to solve this.
var sourceDictionary = {
"200" : [
[ "a", 5 ],
[ "al", 6 ],
[ "xl", 8 ]
],
"201" : [
[ "b", 2 ],
[ "al", 16 ],
[ "al", 26 ],
[ "al", 9 ],
[ "al", 3 ]
],
"202" : [
[ "lm", 7 ]
]
}
I want to sort the dictionary based on the integer values contained within each key and then rank each value,as shown in the outputputDictionary.
var targetDictionary = {
"200" : [
[ "a", 5, "rank-7" ],
[ "al", 6, "rank-6" ],
[ "xl", 8, "rank-4" ]
],
"201" : [
[ "b", 2, "rank-9" ],
[ "al", 16, , "rank-2" ],
[ "al", 26, "rank-1" ],
[ "al", 9, "rank-3" ],
[ "al", 3, "rank-8" ]
],
"202" : [
[ "lm", 7, "rank-5" ]
]
}
For example [ "al", 26, "rank-1" ]
.This is rank-1 as 26 is maximum among all the other values.
Javascript is the most preferable language.Looking for the best optimal solution