Skip to content

Commit

Permalink
style: pefer destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLY201 committed Jun 14, 2023
1 parent 8cf0a0a commit 605e0ba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"plugins": ["compat"],
"rules": {
"no-console": "error",
"compat/compat": "error"
"compat/compat": "error",
"prefer-destructuring": ["error", {
"object": true,
"array": false
}]
}
}
2 changes: 1 addition & 1 deletion src/hash/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export abstract class HashContainer<K, V> extends Container<K | [K, V]> {
}
}
clear() {
const HASH_TAG = this.HASH_TAG;
const { HASH_TAG } = this;
this._objMap.forEach(function (el) {
delete (<Record<symbol, number>><unknown>el._key)[HASH_TAG];
});
Expand Down
17 changes: 10 additions & 7 deletions src/sequential/deque.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class Deque<T> extends SequentialContainer<T> {
for (let i = this._first.x; i < this._bucketNum; ++i) {
newMap[newMap.length] = this._map[i];
}
for (let i = 0; i < this._last.x; ++i) {
const lastX = this._last.x;
for (let i = 0; i < lastX; ++i) {
newMap[newMap.length] = this._map[i];
}
newMap[newMap.length] = [...this._map[this._last.x]];
Expand Down Expand Up @@ -197,13 +198,14 @@ class Deque<T> extends SequentialContainer<T> {
_push(item: T) {
if (this._length > 0) {
this._last = this._getNextPosition(this._last);
if (this._last.x === 0 && this._last.y === 0) {
const { x, y } = this._last;
if (x === 0 && y === 0) {
this._map.push(new Array(this._bucketSize));
this._last = { x: this._bucketNum, y: 0 };
this._bucketNum += 1;
} else if (
this._last.x === this._first.x &&
this._last.y === this._first.y
x === this._first.x &&
y === this._first.y
) this._reAllocate();
}
this._length += 1;
Expand Down Expand Up @@ -233,9 +235,10 @@ class Deque<T> extends SequentialContainer<T> {
_unshift(item: T) {
if (this._length > 0) {
this._first = this._getPrevPosition(this._first);
const { x, y } = this._first;
if (
this._first.x === this._last.x &&
this._first.y === this._last.y
x === this._last.x &&
y === this._last.y
) this._reAllocate();
}
this._length += 1;
Expand Down Expand Up @@ -287,7 +290,7 @@ class Deque<T> extends SequentialContainer<T> {
return this._length;
}
erase(iter: DequeIterator<T>) {
const _node = iter._node;
const { _node } = iter;
if (_node < 0 || _node >= this._length) {
throw new RangeError('Invalid deque iterator!');
}
Expand Down
8 changes: 4 additions & 4 deletions src/sequential/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Vector<T> extends SequentialContainer<T> {
return this._vector[index];
}
erase(iter: VectorIterator<T>) {
const _node = iter._node;
const { _node } = iter;
iter = iter.next();
this.splice(_node, 1);
return iter;
Expand All @@ -112,7 +112,7 @@ class Vector<T> extends SequentialContainer<T> {
this._vector[index] = item;
}
find(item: T, cmp: CompareFn<T> = compareFromS2L) {
const length = this.length;
const { length } = this;
for (let i = 0; i < length; ++i) {
// istanbul ignore else
if (cmp(this._vector[i], item) === 0) {
Expand All @@ -130,7 +130,7 @@ class Vector<T> extends SequentialContainer<T> {
}
unique(cmp: CompareFn<T> = compareFromS2L) {
let index = 1;
const length = this.length;
const { length } = this;
for (let i = 1; i < length; ++i) {
if (cmp(this._vector[i], this._vector[i - 1]) !== 0) {
this._vector[index++] = this._vector[i];
Expand Down Expand Up @@ -193,7 +193,7 @@ class Vector<T> extends SequentialContainer<T> {
return this._vector.values();
}
forEach(callback: (value: T, index: number, container: this) => void) {
const length = this.length;
const { length } = this;
for (let i = 0; i < length; ++i) {
callback(this._vector[i], i, this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export function ceil(a: number, b: number) {
/**
* @internal
*/
export const floor = Math.floor;
export const { floor } = Math;

0 comments on commit 605e0ba

Please sign in to comment.