@@ -24,11 +24,10 @@ var LinkedList = /** @class */ (function () {
24
24
this . EMPTY_NODE = { value : null , next : null } ;
25
25
// private methods
26
26
/**
27
- * Method:
28
27
* Adds wrapped node to the end of the collection
29
28
* 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
32
31
*/
33
32
this . appendToEnd = function ( node ) {
34
33
if ( _this . slength ( ) === 1 ) {
@@ -40,19 +39,22 @@ var LinkedList = /** @class */ (function () {
40
39
_this . tail = node ;
41
40
} ;
42
41
/**
43
- * Method:
44
- * returns length of the collectison
42
+ * @returns length of the collection.
45
43
*/
46
44
this . slength = function ( ) {
47
45
var count = 0 ;
48
46
_this . iterateOver ( function ( _ ) { return count ++ ; } ) ;
49
47
return count ;
50
48
} ;
51
49
/**
52
- * A Generic iterator function which loops over each el in collection
50
+ * A Generic iterator function which loops over each el in collection.
53
51
* and apaplies callback to them along the traverse.
54
52
*
55
53
* 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
56
58
*/
57
59
this . iterateOver = function ( callback , node ) {
58
60
if ( node === void 0 ) { node = _this . head ; }
@@ -63,10 +65,9 @@ var LinkedList = /** @class */ (function () {
63
65
_this . iterateOver ( callback , node . next ) ;
64
66
} ;
65
67
/**
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
70
71
*/
71
72
this . getlTail = function ( node ) {
72
73
if ( node === void 0 ) { node = _this . head . next ; }
@@ -78,10 +79,9 @@ var LinkedList = /** @class */ (function () {
78
79
return temp ;
79
80
} ;
80
81
/**
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
85
85
*/
86
86
this . getlTop = function ( node ) {
87
87
if ( node === void 0 ) { node = _this . head ; }
@@ -93,6 +93,12 @@ var LinkedList = /** @class */ (function () {
93
93
return temp ;
94
94
} ;
95
95
//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
+ */
96
102
this . parseObj = function ( obj ) {
97
103
return JSON . stringify ( obj ) . split ( "," ) . map ( function ( item ) {
98
104
var sp = item . split ( ":" ) ;
@@ -101,15 +107,12 @@ var LinkedList = /** @class */ (function () {
101
107
} ) . join ( "," ) . replace ( / : / g, ": " ) . replace ( / , / g, ", " ) . replace ( / { / g, "{ " ) . replace ( / } / g, " }" ) . replace ( / " / g, "'" ) ;
102
108
} ;
103
109
/**
104
- * Method:
105
- * returns true if collection is empty
110
+ * @returns true if collection is empty
106
111
*/
107
112
this . isEmpty = function ( ) { return ! _this . head ; } ;
108
113
/**
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
113
116
*/
114
117
this . summonNode = function ( value ) {
115
118
return {
@@ -118,11 +121,9 @@ var LinkedList = /** @class */ (function () {
118
121
} ;
119
122
} ;
120
123
/**
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
126
127
*/
127
128
this . append = function ( value ) {
128
129
var node = _this . summonNode ( value ) ;
@@ -135,19 +136,17 @@ var LinkedList = /** @class */ (function () {
135
136
return _this ;
136
137
} ;
137
138
/**
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
142
142
*/
143
143
this . remove = function ( value ) {
144
144
return _this . filter ( function ( i ) { return i !== value ; } ) ;
145
145
} ;
146
146
/**
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
151
150
*/
152
151
this . mRemove = function ( value ) {
153
152
var deleted = false ;
@@ -172,8 +171,8 @@ var LinkedList = /** @class */ (function () {
172
171
return deleted ;
173
172
} ;
174
173
/**
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.
177
176
*/
178
177
this . toLLString = function ( ) {
179
178
var temp = "" ;
@@ -183,8 +182,8 @@ var LinkedList = /** @class */ (function () {
183
182
return temp + "null" ;
184
183
} ;
185
184
/**
186
- * Method:
187
- * returns the list view of the collection.
185
+ * Display the collection as string.
186
+ * @ returns the list view of the collection.
188
187
*/
189
188
this . toString = function ( ) {
190
189
var temp = "[ " ;
@@ -203,32 +202,28 @@ var LinkedList = /** @class */ (function () {
203
202
return temp + "]" ;
204
203
} ;
205
204
/**
206
- * Method:
207
205
* 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 .
210
208
*/
211
209
this . fromArray = function ( arr ) {
212
210
arr . forEach ( _this . append ) ;
213
211
return _this ;
214
212
} ;
215
213
/**
216
- * Method:
217
214
* 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 .
220
217
*/
221
218
this . toArray = function ( ) {
222
219
var temp = [ ] ;
223
220
_this . iterateOver ( function ( _ ) { return temp . push ( _ ) ; } ) ;
224
221
return temp ;
225
222
} ;
226
223
/**
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.
232
227
*/
233
228
this [ "++" ] = function ( list ) {
234
229
var node = list . head ;
@@ -239,21 +234,20 @@ var LinkedList = /** @class */ (function () {
239
234
return _this ;
240
235
} ;
241
236
/**
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.
246
240
*/
247
241
this [ "+" ] = function ( list ) {
248
242
if ( ! list . tail )
249
243
return _this ;
250
244
return _this . append ( list . lhead ) [ "+" ] ( list . ltail ) ;
251
245
} ;
252
246
/**
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 .
257
251
*/
258
252
this . foreach = function ( callback , acc ) {
259
253
if ( acc === void 0 ) { acc = new LinkedList ( ) ; }
@@ -262,10 +256,10 @@ var LinkedList = /** @class */ (function () {
262
256
return _this . ltail . foreach ( callback , acc [ "+" ] ( new LinkedList ( ) . append ( callback ( _this . lhead ) ) ) ) ;
263
257
} ;
264
258
/**
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 .
269
263
*/
270
264
this . mforeach = function ( callback , node ) {
271
265
if ( node === void 0 ) { node = _this . head ; }
@@ -275,30 +269,25 @@ var LinkedList = /** @class */ (function () {
275
269
_this . mforeach ( callback , node . next ) ;
276
270
} ;
277
271
/**
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.
283
275
*/
284
276
this . contains = function ( value ) {
285
277
return _this . filter ( function ( _ ) { return _ === value ; } ) . length > 0 ? true : false ;
286
278
} ;
287
279
/**
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.
293
283
*/
294
284
this . find = function ( predicate ) {
295
285
return _this . filter ( predicate ) . length > 0 ? _this . lhead : null ;
296
286
} ;
297
287
/**
298
- * Method:
288
+ *flatten a single depth of collection
299
289
* @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
302
291
*/
303
292
this . flatten = function ( acc ) {
304
293
if ( acc === void 0 ) { acc = new LinkedList ( ) ; }
@@ -349,11 +338,10 @@ var LinkedList = /** @class */ (function () {
349
338
return this . toString ( ) ;
350
339
} ;
351
340
/**
352
- * Method:
353
341
* 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.
357
345
*/
358
346
LinkedList . prototype . testMap = function ( callback , node ) {
359
347
if ( node === void 0 ) { node = this . head ; }
@@ -367,10 +355,10 @@ var LinkedList = /** @class */ (function () {
367
355
// TODO: implement filter and reduce.....
368
356
// make these methods functional
369
357
/**
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.
374
362
*/
375
363
LinkedList . prototype . map = function ( callback , acc ) {
376
364
if ( acc === void 0 ) { acc = new LinkedList ( ) ; }
@@ -380,10 +368,10 @@ var LinkedList = /** @class */ (function () {
380
368
return this . ltail . map ( callback , acc [ "+" ] ( new LinkedList ( ) . append ( callback ( this . lhead ) ) ) ) ;
381
369
} ;
382
370
/**
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.
387
375
*/
388
376
LinkedList . prototype . filter = function ( callback , acc ) {
389
377
if ( acc === void 0 ) { acc = new LinkedList ( ) ; }
@@ -392,10 +380,10 @@ var LinkedList = /** @class */ (function () {
392
380
return callback ( this . lhead ) ? this . ltail . filter ( callback , acc [ "+" ] ( new LinkedList ( ) . append ( this . lhead ) ) ) : this . ltail . filter ( callback , acc ) ;
393
381
} ;
394
382
/**
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.
399
387
*/
400
388
LinkedList . prototype . reduce = function ( callback , acc ) {
401
389
if ( acc === void 0 ) { acc = null ; }
@@ -404,11 +392,10 @@ var LinkedList = /** @class */ (function () {
404
392
return this . ltail . reduce ( callback , callback ( this . lhead , acc ) ) ;
405
393
} ;
406
394
/**
407
- * Method:
408
395
* A monadic feature that maps and then flattens the collection.
409
396
* @param callback function executed for the elements in the collection
410
397
* @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
412
399
*/
413
400
LinkedList . prototype . flatmap = function ( callback , acc ) {
414
401
if ( acc === void 0 ) { acc = new LinkedList ( ) ; }
0 commit comments