function add(key, value){
this.dataStore[key] = value;
}
function show(){
for(var key in this.dataStore){
console.log(key + " : " + this.dataStore[key]);
}
}
function find(key){
return this.dataStore[key];
}
function remove(key){
delete this.dataStore[key];
}
function count(){
var n = 0;
for(var key in Object.keys(this.dataStore)){
++n;
}
return n;
}
function kSort(){
var dic = this.dataStore;
var res = Object.keys(dic).sort();
for(var key in res ){
console.log(res[key] + " : " + dic[res[key]]);
}
}
function vSort(){
var dic = this.dataStore;
var res = Object.keys(dic).sort(function(a,b){
return dic[a]-dic[b];
});
for(var key in res ){
console.log(res[key] + " : " + dic[res[key]]);
}
}
function clear(){
for(var key in this.dataStore){
delete this.dataStore[key];
}
}
function Dictionary(){
this.dataStore = new Array();
this.add = add;
this.show = show;
this.find = find;
this.remove = remove;
this.count = count;
this.kSort = kSort;
this.vSort = vSort;
this.clear = clear;
}
var stu = new Dictionary();
stu.add('ben','45');
stu.add('jone','23');
stu.add('alice','56');
stu.add('wendy','85');
stu.add('lily','44');
stu.show();
console.log('------------');
stu.vSort();
stu.show();
console