Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulelhakim68@gmail.com committed Jan 23, 2024
1 parent 10ed84a commit 6dd596d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
28 changes: 14 additions & 14 deletions src/list-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ export interface AbstractIterator<T> extends Iterable<T> {
* @type {() => this}
*/
first: () => this;

/**
* Sets current position to last element of list
* @date 1/23/2024 - 7:19:25 PM
*
* @type {() => this}
*/
last: () => this;

/**
* Moves current position back one element
* @date 1/23/2024 - 7:20:09 PM
*
* @type {() => this}
*/
previous: () => this;

/**
* Moves current position forward one element
* @date 1/23/2024 - 7:20:25 PM
*
* @type {() => this}
*/
next: () => this;

/**
* Returns the current position in list
* @date 1/23/2024 - 7:20:39 PM
*
* @type {() => number}
*/
current: () => number;

/**
* Moves the current position to specified position
* @date 1/23/2024 - 7:21:14 PM
Expand All @@ -63,32 +63,32 @@ export class AbstractListIterator<List> implements AbstractIterator<List> {
return this;
}

public next(): this{
public next(): this {
// this.position
if(this.position < this.length -1){
++this.position
if (this.position < this.length - 1) {
++this.position;
}
return this;
}

public previous(): this{
if(this.position > 0){
public previous(): this {
if (this.position > 0) {
--this.position;
}
return this;
}

public current () {
public current() {
return this.position;
}

public last(): this{
public last(): this {
this.position = this.length - 1;
return this;
}

public moveTo (position: number): this {
public moveTo(position: number): this {
this.position = position - 1;
return this;
}
}
}
14 changes: 7 additions & 7 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { AbstractIterator, AbstractListIterator } from "./list-iterator";

/* eslint-disable @typescript-eslint/no-inferrable-types */
export interface AbstractList<List> extends AbstractIterator<List>{
export interface AbstractList<List> extends AbstractIterator<List> {
/**
* Determine Number of elements in list
* @date 1/23/2024 - 12:53:11 PM
Expand Down Expand Up @@ -46,7 +46,7 @@ export interface AbstractList<List> extends AbstractIterator<List>{
*
* ```
*/
getElement: () => List|undefined;
getElement: () => List | undefined;

/**
* Inserting an Element into a List
Expand Down Expand Up @@ -135,17 +135,17 @@ export interface AbstractList<List> extends AbstractIterator<List>{
export class List<T> extends AbstractListIterator<T> {
public size: number = 0;
private _context: Array<T> = [];
public contains (element: T extends any ? T : never) : boolean {
for(let i = 0; i < this.length; ++i){
if(this.context[i] === element){

public contains(element: T extends any ? T : never): boolean {
for (let i = 0; i < this.length; ++i) {
if (this.context[i] === element) {
return true;
}
}
return false;
}

public clear() : void {
public clear(): void {
this._context = [];
this.size = this.position = this.length = 0;
}
Expand Down
14 changes: 7 additions & 7 deletions test/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ describe("List", () => {
personLists.previous();
expect(personLists.getElement()).toStrictEqual({
name: "person2",
age: 20
})
age: 20,
});
personLists.previous();
expect(personLists.getElement()).toStrictEqual({
name: "person1",
age: 10
})
age: 10,
});
});

it("call ``moveTo`` any ways should return correct element for that position", () => {
Expand All @@ -218,10 +218,10 @@ describe("List", () => {
personLists.moveTo(3);
expect(personLists.getElement()).toStrictEqual({
name: "person3",
age: 30
})
age: 30,
});
expect(personLists.current()).toStrictEqual(personLists.position);
})
});
});
describe("Utils Methods Call", () => {
it("Call ``toString()`` should can return string represent the list", () => {
Expand Down

0 comments on commit 6dd596d

Please sign in to comment.