const array1 = [1,2,3,1,3,5];
const reducer = (accumulator, currentValue,idx) =>{
if(!(currentValue in accumulator)){
accumulator[currentValue]=[idx];
}else{
accumulator[currentValue].push(idx);
}
return accumulator;
};
console.log(array1.reduce(reducer,{}));
何だせっかく考えたのに
(https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
a = [1,2,3,1,3,5]っていう配列を各要素ごとにIndexを抽出したいんだけど(1なら0と3、2なら1) var newArray; //intの多次元配列 For(…){ if (aに重複チェック){ newArray[重複Index].Add(...
const array1 = [1,2,3,1,3,5]; const reducer = (accumulator, currentValue,idx) =>{ if(!(currentValue in accumulator)){ accumulator[currentValue]=[idx]; }else{accumulator[currentValue].push(idx); } return accumulator; }; console.log(array...
ありがとう! 計算コストが安くなりそうだから使う!
最強だったわ ありがとう
いいってことよ