Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- TypeScript
- react
- descendingOrder
- type
- java api
- useEffect
- TABLESPACE
- DB2
- Debug
- codewar
- IBM
- react hook
- codewars
- custom hook
- manifest.json
- JDBC
- isSquare
Archives
- Today
- Total
taesik
retrun true if every value in the array has its corresponding value squared in the secone array. 본문
functions and trick/typescript_javascript
retrun true if every value in the array has its corresponding value squared in the secone array.
taesikk 2022. 4. 29. 09:36The frequency of values must be same.
function same(arr1, arr2){
if(arr1.length !== arr2.length){
return false;
}
let frequencyCounter1 = {}
let frequencyCounter2 = {}
for(let val of arr1){
frequencyCounter1[val] = (frequencyCounter1[val] || 0) + 1
}
for(let val of arr2){
frequencyCounter2[val] = (frequencyCounter2[val] || 0) + 1
}
console.log(frequencyCounter1);
console.log(frequencyCounter2);
for(let key in frequencyCounter1){
if(!(key ** 2 in frequencyCounter2)){
return false
}
if(frequencyCounter2[key ** 2] !== frequencyCounter1[key]){
return false
}
}
return true
}
same([1,2,3,2,5], [9,1,4,4,11])'functions and trick > typescript_javascript' 카테고리의 다른 글
| Write a function called sumZero which accepts a sorted array of integers. (0) | 2022.04.29 |
|---|---|
| check if two strings are ANAGRAM (using frequencyCounter) (0) | 2022.04.29 |
| Counting Duplicates (0) | 2022.01.29 |
| Backspaces in string (0) | 2022.01.29 |
| Consecutive strings (0) | 2022.01.29 |