Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commita237cf2

Browse files
committed
Add alternate implementation of forEach
1 parentaf5a639 commita237cf2

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

‎arrayStringMap.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ describe("Map with two objects", () => {
250250
it("Map forEach is called twice",()=>{
251251
letcount=0;
252252
arrayStringMap.forEach((value,key,map)=>{
253-
count++;
254253
assert(map===arrayStringMap,"Map is arrayStringMap");
255254
if(count===0){
256255
assert(key===sampleArray1,"Key is sampleArray1");
@@ -260,6 +259,7 @@ describe("Map with two objects", () => {
260259
assert(key===sampleArray3,"Key is sampleArray3");
261260
assert(value===sampleValue2,"Value is sampleValue2");
262261
}
262+
count++;
263263
});
264264
assert(count===2,"ForEach is called twice");
265265
})

‎arrayStringMap.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ export default class ArrayStringMap<K extends any[], V> implements Map<K, V> {
5151
}
5252

5353
forEach(callbackfn:(value:V,key:K,map:ArrayStringMap<K,V>)=>void,thisArg?:any):void{
54-
this._converterInfo.forEach((value,key)=>{
55-
// TypeScript complains that this will be undefined, but the items in
56-
// `this._converterInfo` and `this._map` will always be defined in each other.
57-
returncallbackfn(this._map.get(key)!,value,thisArg);
58-
});
54+
for(const[key,value]ofthis.entries()){
55+
callbackfn.call(thisArg,value,key,this);
56+
}
5957
}
6058

6159
get(key:K):V|undefined{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp