Skip to content

Commit

Permalink
feat: add CharactersCollection class to manage bubble sort algorithm …
Browse files Browse the repository at this point in the history
…when a sequence of strings is given
  • Loading branch information
dEzequiel committed Apr 21, 2022
1 parent aa1034b commit c454e64
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/CharactersCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Sortable } from "./interfaces/Sortable";

export class CharactersCollection implements Sortable {

collection: string = '';
newValue: string = '';

constructor(collection: string) {
this.collection = collection;
}

get length(): number {
return this.collection.length;
}

swap(leftIndex: number, rightIndex: number): void {
const characters = this.collection.split('');
let swap = characters[leftIndex];

characters[leftIndex] = characters[rightIndex];
characters[rightIndex] = swap;

this.collection = characters.join('');

}
compare(leftIndex: number, rightIndex: number): boolean {
return this.collection[leftIndex] > this.collection[rightIndex];
}


}

0 comments on commit c454e64

Please sign in to comment.