You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constarray=[1,2,3,4,5];consthasEven=array.some((element)=>element%2===0);// 必ず配列全体を走査するため、一般には some メソッドより効率が悪いconsthasEvenByReduce=array.reduce((acc,element)=>acc||Boolean(element%2===0),false);
every メソッドを reduce メソッドで再現する
constarray=[1,2,3,4,5];constallOdd=array.every((element)=>element%2===1);// 必ず配列全体を走査するため、一般には every メソッドより効率が悪いconstallOddByReduce=array.reduce((acc,element)=>acc&&Boolean(element%2===1),true);
// includes メソッドconstarray=[1,2,3,4,5];consthasValue=array.includes(3);// 必ず配列全体を走査するため、一般には includes メソッドより効率が悪いconsthasValueByReduce=array.reduce((acc,element)=>acc||element===3,false);