Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Add alternate implementation of forEach #8

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion arrayStringMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ describe("Map with two objects", () => {
it("Map forEach is called twice", () => {
let count = 0;
arrayStringMap.forEach((value, key, map) => {
count++;
assert(map === arrayStringMap, "Map is arrayStringMap");
if (count === 0){
assert(key === sampleArray1, "Key is sampleArray1");
Expand All @@ -260,6 +259,7 @@ describe("Map with two objects", () => {
assert(key === sampleArray3, "Key is sampleArray3");
assert(value === sampleValue2, "Value is sampleValue2");
}
count++;
});
assert(count === 2, "ForEach is called twice");
})
Expand Down
8 changes: 3 additions & 5 deletions arrayStringMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ export default class ArrayStringMap<K extends any[], V> implements Map<K, V> {
}

forEach(callbackfn: (value: V, key: K, map: ArrayStringMap<K, V>) => void, thisArg?: any): void {
this._converterInfo.forEach((value, key) => {
// TypeScript complains that this will be undefined, but the items in
// `this._converterInfo` and `this._map` will always be defined in each other.
return callbackfn(this._map.get(key)!, value, thisArg);
});
for (const [key, value] of this.entries()) {
callbackfn.call(thisArg, value, key, this);
}
}

get(key: K): V | undefined {
Expand Down