There is nothing wrong with the code below. However, issue is I cannot understand this line here frequencyCounter1[iteration] = (frequencyCounter1[iteration] || 0) + 1
properly
**frequencyCounter1[iteration]** = (*frequencyCounter1[iteration]* || 0) + 1
So this is setting frequencyCounter1[iteration] key to the object but in ITALIC = (frequencyCounter1[iteration] || 0) + 1 it is valute to the object
why this code frequencyCounter1[iteration] is a key and value of a key at the same time ??
function same(arr1, arr2) {
if(!arr1 && arr2) {
return false
};
if(arr1.length !== arr2.length) {
return false
};
let frequencyCounter1 = {};
let frequencyCounter2 = {};
for (let iteration of arr1) {
frequencyCounter1[iteration] = (frequencyCounter1[iteration] || 0) + 1
console.log(frequencyCounter1)
};
for (let iteration of arr2) {
frequencyCounter2[iteration] = (frequencyCounter2[iteration] || 0) + 1
};
for(let key in frequencyCounter1) {
console.log(key)
if (!(key ** 2 in frequencyCounter2)){
return false
}
if (frequencyCounter2[key ** 2] !== frequencyCounter1[key]){
return false
}
}
return true
};
console.log(same([2,2,2,5,3,6], [4,4,4,25,9,36]))