Skip to content

Commit d290821

Browse files
committed
Fix the doc string and integrate jest for tests.
1 parent 4e5c12b commit d290821

File tree

7 files changed

+6310
-652
lines changed

7 files changed

+6310
-652
lines changed

build/ll.js

+78-91
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ var LinkedList = /** @class */ (function () {
2424
this.EMPTY_NODE = { value: null, next: null };
2525
// private methods
2626
/**
27-
* Method:
2827
* Adds wrapped node to the end of the collection
2928
* Parameter:
30-
* node(Node): node wrapper for each collection unit
31-
* returns void
29+
* @param node (Node): node wrapper for each collection unit
30+
* @returns void
3231
*/
3332
this.appendToEnd = function (node) {
3433
if (_this.slength() === 1) {
@@ -40,19 +39,22 @@ var LinkedList = /** @class */ (function () {
4039
_this.tail = node;
4140
};
4241
/**
43-
* Method:
44-
* returns length of the collectison
42+
* @returns length of the collection.
4543
*/
4644
this.slength = function () {
4745
var count = 0;
4846
_this.iterateOver(function (_) { return count++; });
4947
return count;
5048
};
5149
/**
52-
* A Generic iterator function which loops over each el in collection
50+
* A Generic iterator function which loops over each el in collection.
5351
* and apaplies callback to them along the traverse.
5452
*
5553
* Able to perform sideeffects
54+
*
55+
* @param callback A transform applied to each el in collection.
56+
* @param node (Node) wrapper for each list component.
57+
* @returns void
5658
*/
5759
this.iterateOver = function (callback, node) {
5860
if (node === void 0) { node = _this.head; }
@@ -63,10 +65,9 @@ var LinkedList = /** @class */ (function () {
6365
_this.iterateOver(callback, node.next);
6466
};
6567
/**
66-
* Method
67-
* parameter:
68-
* node(Node<T>): node of the collection
69-
* returns the list of collection except the head unit
68+
* IT simply return the collection excluding the head el(first element).
69+
* @param node (Node<T>): node of the collection
70+
* @returns the list of collection except the head unit
7071
*/
7172
this.getlTail = function (node) {
7273
if (node === void 0) { node = _this.head.next; }
@@ -78,10 +79,9 @@ var LinkedList = /** @class */ (function () {
7879
return temp;
7980
};
8081
/**
81-
* Method
82-
* parameter:
83-
* node(Node<T>): node of the collection
84-
* returns the list of collection except the tail unit
82+
* Method return the collection excluing the tail el(last element).
83+
* @param node (Node<T>): node of the collection
84+
* @returns the list of collection except the tail unit
8585
*/
8686
this.getlTop = function (node) {
8787
if (node === void 0) { node = _this.head; }
@@ -93,6 +93,12 @@ var LinkedList = /** @class */ (function () {
9393
return temp;
9494
};
9595
//utility for toSting method
96+
/**
97+
* Parses the object type of js to string.
98+
* @param obj an object type to be transformed
99+
* Note: obj refers to object not Object
100+
* @returns stringified object
101+
*/
96102
this.parseObj = function (obj) {
97103
return JSON.stringify(obj).split(",").map(function (item) {
98104
var sp = item.split(":");
@@ -101,15 +107,12 @@ var LinkedList = /** @class */ (function () {
101107
}).join(",").replace(/:/g, ": ").replace(/,/g, ", ").replace(/{/g, "{ ").replace(/}/g, " }").replace(/"/g, "'");
102108
};
103109
/**
104-
* Method:
105-
* returns true if collection is empty
110+
* @returns true if collection is empty
106111
*/
107112
this.isEmpty = function () { return !_this.head; };
108113
/**
109-
* Method:
110-
* parameters:
111-
* value(T) => type of unit of collection
112-
* return a Node with the given value
114+
* @param value (T) => type of unit of collection
115+
* @returns a Node with the given value
113116
*/
114117
this.summonNode = function (value) {
115118
return {
@@ -118,11 +121,9 @@ var LinkedList = /** @class */ (function () {
118121
};
119122
};
120123
/**
121-
* Method:
122-
* Appends the value to the end of the collection
123-
* parameters:
124-
* value(T) => type of unit of collection
125-
* return a LinkedList collection of the items
124+
* Appends the value to the end of the collection.
125+
* @param value (T) => type of unit of collection
126+
* @returns a LinkedList collection of the items
126127
*/
127128
this.append = function (value) {
128129
var node = _this.summonNode(value);
@@ -135,19 +136,17 @@ var LinkedList = /** @class */ (function () {
135136
return _this;
136137
};
137138
/**
138-
* Method:
139-
* parameter:
140-
* value(T): value to be removed
141-
* returns a new collection
139+
* Remove the element if exists in collection.
140+
* @param value(T): value to be removed
141+
* @returns a new collection without the eremoved element
142142
*/
143143
this.remove = function (value) {
144144
return _this.filter(function (i) { return i !== value; });
145145
};
146146
/**
147-
* Method:
148-
* parameter:
149-
* value(T): value to be removed
150-
* returns boolean as result of operation
147+
* Mutable removal of the provided element.
148+
* @param value (T): value to be removed
149+
* @returns boolean as result of operation
151150
*/
152151
this.mRemove = function (value) {
153152
var deleted = false;
@@ -172,8 +171,8 @@ var LinkedList = /** @class */ (function () {
172171
return deleted;
173172
};
174173
/**
175-
* Method:
176-
* returns the typical linked list view of the collection.
174+
* Display the intuitive representation of LinkedList.
175+
* @returns the typical linked list view of the collection.
177176
*/
178177
this.toLLString = function () {
179178
var temp = "";
@@ -183,8 +182,8 @@ var LinkedList = /** @class */ (function () {
183182
return temp + "null";
184183
};
185184
/**
186-
* Method:
187-
* returns the list view of the collection.
185+
* Display the collection as string.
186+
* @returns the list view of the collection.
188187
*/
189188
this.toString = function () {
190189
var temp = "[ ";
@@ -203,32 +202,28 @@ var LinkedList = /** @class */ (function () {
203202
return temp + "]";
204203
};
205204
/**
206-
* Method:
207205
* converts Array to LinkedList collection.
208-
* parameter:
209-
* arr(Array<T>): Array of unit type T.
206+
* @param arr (Array<T>): Array of unit type T.
207+
* @returns a LinkedList form of the default array type of js.
210208
*/
211209
this.fromArray = function (arr) {
212210
arr.forEach(_this.append);
213211
return _this;
214212
};
215213
/**
216-
* Method:
217214
* converts Array to LinkedList collection.
218-
* parameter:
219-
* arr(Array<T>): Array of unit type T.
215+
* @param arr (Array<T>): Array of unit type T.
216+
* @returns the default array version of the collection.
220217
*/
221218
this.toArray = function () {
222219
var temp = [];
223220
_this.iterateOver(function (_) { return temp.push(_); });
224221
return temp;
225222
};
226223
/**
227-
* Method:
228-
* non-recursive implementation
229-
* parameter:
230-
* list(LinkedList<T>): list needed to be appended to the end
231-
* returns the transformed or mapped collection of linkedList itself.
224+
* Note: non-recursive implementation
225+
* @param list (LinkedList<T>): list needed to be appended to the end
226+
* @returns the transformed or mapped collection of linkedList itself.
232227
*/
233228
this["++"] = function (list) {
234229
var node = list.head;
@@ -239,21 +234,20 @@ var LinkedList = /** @class */ (function () {
239234
return _this;
240235
};
241236
/**
242-
* Method:
243-
* parameter:
244-
* list(LinkedList<T>): list needed to be appended to the end
245-
* returns the transformed or mapped collection of linkedList itself.
237+
* Adds to LinkedList together just like string concat.
238+
* @param list (LinkedList<T>): list needed to be appended to the end
239+
* @returns the transformed or mapped collection of linkedList itself.
246240
*/
247241
this["+"] = function (list) {
248242
if (!list.tail)
249243
return _this;
250244
return _this.append(list.lhead)["+"](list.ltail);
251245
};
252246
/**
253-
* Method:
254-
* converts Array to LinkedList collection.
255-
* parameter:
256-
* arr(Array<T>): Array of unit type T.
247+
* Applies the callback to each el in the collection
248+
* @param arr (Array<T>): Array of unit type T.
249+
* @param acc accumulator defaults to empty linkedlist.
250+
* @returns the collection applied to callback for each el.
257251
*/
258252
this.foreach = function (callback, acc) {
259253
if (acc === void 0) { acc = new LinkedList(); }
@@ -262,10 +256,10 @@ var LinkedList = /** @class */ (function () {
262256
return _this.ltail.foreach(callback, acc["+"](new LinkedList().append(callback(_this.lhead))));
263257
};
264258
/**
265-
* Method:
266-
* converts Array to LinkedList collection.
267-
* parameter:
268-
* arr(Array<T>): Array of unit type T.
259+
* Converts Array to LinkedList collection.:
260+
* @param arr (Array<T>): Array of unit type T.
261+
* @param node Defaults to head of collection.
262+
* @returns the mutated collection.
269263
*/
270264
this.mforeach = function (callback, node) {
271265
if (node === void 0) { node = _this.head; }
@@ -275,30 +269,25 @@ var LinkedList = /** @class */ (function () {
275269
_this.mforeach(callback, node.next);
276270
};
277271
/**
278-
* Method:
279-
* checks if collection contains the item
280-
* parameter:
281-
* value(T): find if value exist in the collection
282-
* returns boolean as per result.
272+
* Checks if collection contains the item.
273+
* @param value (T): find if value exist in the collection.
274+
* @returns boolean as per result.
283275
*/
284276
this.contains = function (value) {
285277
return _this.filter(function (_) { return _ === value; }).length > 0 ? true : false;
286278
};
287279
/**
288-
* Method:
289-
* returns the first item found as per predicate
290-
* parameter:
291-
* predicate: function to filter the collection
292-
* returns value if found else null
280+
* Returns the first item found as per predicate.
281+
* predicate: function to filter the collection.
282+
* @returns value if found else null.
293283
*/
294284
this.find = function (predicate) {
295285
return _this.filter(predicate).length > 0 ? _this.lhead : null;
296286
};
297287
/**
298-
* Method:
288+
*flatten a single depth of collection
299289
* @param acc accumulator to flatten the given collection
300-
* flatten a single depth of collection
301-
* returns a flatten linkedList of the elements
290+
* @returns a flatten linkedList of the elements
302291
*/
303292
this.flatten = function (acc) {
304293
if (acc === void 0) { acc = new LinkedList(); }
@@ -349,11 +338,10 @@ var LinkedList = /** @class */ (function () {
349338
return this.toString();
350339
};
351340
/**
352-
* Method:
353341
* Non functional implementation of map
354-
* parameter:
355-
* feature: A call back method applied for each element of the collection.
356-
* returns the transformed or mapped collection of linkedList itself.
342+
* @param callback : A call back method applied for each element of the collection.
343+
* @param node defults to head of the collection.
344+
* @returns the transformed or mapped collection of linkedList itself.
357345
*/
358346
LinkedList.prototype.testMap = function (callback, node) {
359347
if (node === void 0) { node = this.head; }
@@ -367,10 +355,10 @@ var LinkedList = /** @class */ (function () {
367355
// TODO: implement filter and reduce.....
368356
// make these methods functional
369357
/**
370-
* Method:
371-
* parameter:
372-
* feature: A call back method applied for each element of the collection.
373-
* returns the transformed or mapped collection of linkedList itself.
358+
* Transform a collection of one domain or type to another.
359+
* @param callback: A call back method applied for each element of the collection.
360+
* @param acc accumulator defaults to empty linkedlist.
361+
* @returns the transformed or mapped collection of linkedList itself.
374362
*/
375363
LinkedList.prototype.map = function (callback, acc) {
376364
if (acc === void 0) { acc = new LinkedList(); }
@@ -380,10 +368,10 @@ var LinkedList = /** @class */ (function () {
380368
return this.ltail.map(callback, acc["+"](new LinkedList().append(callback(this.lhead))));
381369
};
382370
/**
383-
* Method:
384-
* parameter:
385-
* feature: A predicate callback method applied for each element of the collection.
386-
* returns the filterd collection of linkedList itself which passes the predicate.
371+
* Filter the el from the collection satisfying the predicate.
372+
* @param callback: A predicate callback method applied for each element of the collection.
373+
* @param acc accumulator defaults to empty linkedlist.
374+
* @returns the filterd collection of linkedList itself which passes the predicate.
387375
*/
388376
LinkedList.prototype.filter = function (callback, acc) {
389377
if (acc === void 0) { acc = new LinkedList(); }
@@ -392,10 +380,10 @@ var LinkedList = /** @class */ (function () {
392380
return callback(this.lhead) ? this.ltail.filter(callback, acc["+"](new LinkedList().append(this.lhead))) : this.ltail.filter(callback, acc);
393381
};
394382
/**
395-
* Method:
396-
* parameter:
397-
* feature: A predicate callback method applied for each element of the collection.
398-
* returns the reduced collection of linkedList itself which passes the predicate.
383+
* Reduce the collection to a single value transformed with callback anad accumulated.
384+
* @param callback: A predicate callback method applied for each element of the collection.
385+
* @param acc accumulator defaults to null.
386+
* @returns the reduced collection of linkedList itself which passes the predicate.
399387
*/
400388
LinkedList.prototype.reduce = function (callback, acc) {
401389
if (acc === void 0) { acc = null; }
@@ -404,11 +392,10 @@ var LinkedList = /** @class */ (function () {
404392
return this.ltail.reduce(callback, callback(this.lhead, acc));
405393
};
406394
/**
407-
* Method:
408395
* A monadic feature that maps and then flattens the collection.
409396
* @param callback function executed for the elements in the collection
410397
* @param acc oprtional parameter to accumulate the flatten collection.
411-
* returns the flatten collection after being mapped
398+
* @returns the flatten collection after being mapped
412399
*/
413400
LinkedList.prototype.flatmap = function (callback, acc) {
414401
if (acc === void 0) { acc = new LinkedList(); }

build/stack.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ var Stack = /** @class */ (function () {
2323
this.stack = null;
2424
//methods
2525
/**
26-
* @param value push element into the stack
26+
* Add value at top of the stack.
27+
* @param value push element into the stack.
28+
* @returns A stack object with the item at top.
2729
*/
2830
this.push = function (value) {
2931
_this.stack = new ll_1.LinkedList().append(value)["+"](_this.stack);
3032
return _this;
3133
};
3234
/**
33-
* returns the element at top of the stack
35+
* Removes the element from top of stack.
36+
* @returns the element at top of the stack
3437
*/
3538
this.pop = function () {
3639
var t = _this.stack.lhead;
@@ -40,6 +43,7 @@ var Stack = /** @class */ (function () {
4043
/**
4144
* Adds a pile of stack one on top of other.
4245
* @param s Stack of type T to be piled on top
46+
* @returns A stack obj piled on other.
4347
*/
4448
this.pile = function (s) {
4549
_this.stack = _this.stack["+"](s.stack);
@@ -48,6 +52,7 @@ var Stack = /** @class */ (function () {
4852
/**
4953
* Remove a pile of stack from top of stack.
5054
* @param n number of element of stack to be removed.
55+
* @returns A stack obj with n element poped
5156
*/
5257
this.unPile = function (n) {
5358
if (n > _this.stack.length)

0 commit comments

Comments
 (0)