GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaScript-Lessons/Data_Structures/Dictionaries/main.js at master · gurucharanD/JavaScript-Lessons

Expand file tree

/

main.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
73 lines (57 loc) · 1.6 KB
/

main.js

Copy path

File metadata and controls

73 lines (57 loc) · 1.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
function Dictionary() {
var items = {};
// set value to key property of items object
this.set = function (key, value) {
items[key] = value;
};
// first search for key then delete it
this.delete = function (key) {
if(this.has(key)){
delete items[key];
return true;
}
return false;
};
this.has = function (key) {
return key in items;
};
// if value exists then return it, if not return undefined
this.get = function (key) {
return this.has(key) ? items[key] : undefined;
};
this.getItems = function () {
return items;
};
// to return the size of the array, you calculate the size of all the keys
this.size = function () {
return Object.keys(items).length;
};
this.keys = function () {
return Object.keys(items);
};
// to return an array of values only, iterate through all items and access values via the keys
this.values = function () {
var values = [];
for(var k in items){
if(this.has(k)){
values.push(items[k]);
}
}
return values;
};
}
var dict = new Dictionary();
dict.set('Bucky', '[email protected]');
dict.set('Sally', '[email protected]');
dict.set('Tuna', '[email protected]');
console.log(dict.keys());
console.log(dict.values());
console.log(dict.get('Bucky'));
console.log('----------');
dict.delete('Sally');
console.log(dict.keys());
console.log(dict.values());
console.log('----------');
console.log(dict.getItems());
console.log(dict.size());
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.