Skip to content

Commit

Permalink
adding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulelhakim68@gmail.com committed Jan 23, 2024
1 parent 9a95d28 commit 1f90519
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,42 @@ export interface AbstractList<List> {
*
* @public
* @property
* @type {() => List}
* @returns List
*/
getElement: () => List;


/**
* Inserting an Element into a List
*
* @public
* @param {(List extends any ? List : never)} element The element being inserted.
* @param {(List extends any ? List : never)?} after The element that will be using to reference position to inserting a new element (optional).
* @returns List | boolean | undefined
*
* @example
* ```
* interface Person {
* name: string,
* age: number
* }
*
* const personLists = new List<Partial<Person>>();
* personLists.appends([
* {
* name: "hakim1",
* age: 10,
* },
* {
* name: "hanan",
* age: 10,
* },
* ]);
* personLists.insert({
* name: "insert",
* age: 20,
* });
* ```
*/
insert: (
element: List extends any ? List : never,
after?: List extends any ? List : never,
Expand Down Expand Up @@ -91,7 +123,7 @@ export interface AbstractList<List> {
*
* @public
* @method
* @param {(value: List, index: number, obj: List[]) => unknown} predicate
* @param {(value: List, index: number, obj: List[]) => unknown} predicate The predicate function that will compute to find the matches element in givent args
* @param {?*} [thisArg]
* @returns {(List | undefined)}
*/
Expand Down Expand Up @@ -137,6 +169,9 @@ export class List<T> implements AbstractList<T extends any ? T : never> {
return this.context[this.position];
}

/**
* @inheritdoc
*/
public insert(
element: (T extends any ? T : never) extends any
? T extends any
Expand All @@ -153,9 +188,9 @@ export class List<T> implements AbstractList<T extends any ? T : never> {
): boolean | (T extends any ? T : never) | undefined {
// if ``after`` argument given, doing some computation befoere inserting.
if (after) {
const foundAfter = this.find((el) => this.isEquals(el, after as T));
const afterId = this._context.indexOf(foundAfter as T);
this.context.splice(afterId + 1, 0, element);
const afterTarget = this.find((el) => this.isEquals(el, after as T));
const afterInsertPos = this._context.indexOf(afterTarget as T);
this.context.splice(afterInsertPos + 1, 0, element);
++this.size;
++this.length;
return true;
Expand Down

0 comments on commit 1f90519

Please sign in to comment.