var func=(function(){
var users = {
"1": {
"balance": 300,
"name": "Юрий"
},"2": {
"balance": 399,
"name": "Юрий"
},"3": {
"balance": 3000,
"name": "Юрий"
},"4": {
"balance": 5000,
"name": "Юрий"
},"5": {
"balance": 5001,
"name": "Юрий"
},"6": {
"balance": 5000,
"name": "Юрий"
},"7": {
"balance": 5e9,
"name": "Юрий"
}
},
sortedList=Object.keys(users).sort((a,b)=>users[a].balance-users[b].balance);
return {
getUserByPosition:function(position){
return --position in sortedList?users[sortedList[position]]:null;
},
getPositionByUserId:function(userId){
var result=sortedList.indexOf(userId+'');
return result<0?null:result+1;
}
};
})();
console.log(func.getPositionByUserId(5));