Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 52 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
class Sorter {
constructor() {
// your implementation
}
constructor() {
this.arr = [];
this.compareFunction = (a, b) => a - b;
}

add(element) {
// your implementation
}
get length() {
return this.arr.length;
}

at(index) {
// your implementation
}
add(element) {
this.arr.push(element);
}

get length() {
// your implementation
}
at(index) {
return this.arr[index];
}

toArray() {
// your implementation
}
toArray() {
return this.arr;
}

sort(indices) {
// your implementation
}
sort(indices) {
let sortedPart = [];
indices.sort((a, b) => a - b);

setComparator(compareFunction) {
// your implementation
}
for (let i in indices) {
sortedPart.push(this.arr[indices[i]]);
}

sortedPart.sort(this.compareFunction);

for (let i = 0; i < indices.length; i++) {
this.arr[indices[i]] = sortedPart[i];
}
return this.arr;
}

setComparator(compareFunction) {
compareFunction == undefined ? null : this.compareFunction = compareFunction;
}
}


/*let sorter = new Sorter();
sorter.add(5);
sorter.add(4);
sorter.add(3);
console.log(sorter.toArray());
sorter.sort([0, 1, 2]);
console.log(sorter.toArray());
console.log(sorter.length);
console.log(typeof sorter);
sorter.add(1);
sorter.add(2);
sorter.add(3);
sorter.sort[0, 1, 2];
sorter.sort([0]);
console.log(sorter.toArray());
console.log(sorter.toArray() == [1])*/

module.exports = Sorter;