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 | 29 | 30 | 31 |
Tags
- useEffect
- custom hook
- TABLESPACE
- codewar
- TypeScript
- react hook
- type
- manifest.json
- IBM
- codewars
- DB2
- descendingOrder
- JDBC
- isSquare
- react
- java api
- Debug
Archives
- Today
- Total
taesik
check if two strings are ANAGRAM (using frequencyCounter) 본문
functions and trick/typescript_javascript
check if two strings are ANAGRAM (using frequencyCounter)
taesikk 2022. 4. 29. 09:39An anagram is a word, phrase, or name formed by rearranging the letters of another.
function validAnagram(first,second){
// add whatever parameters you deem necessary - good luck!
if(first.length !== second.length) return false;
let lookup = {};
for (let val of first.split('')) {
lookup[val]? lookup[val] += 1 : lookup[val] = 1;
}
for(let val of second.split('')) {
//can't find letter or letter is zero then it's not an anagram
if(!lookup[val]) return false;
else {
lookup[val] -= 1;
}
}
return true;
}
'functions and trick > typescript_javascript' 카테고리의 다른 글
Implement a function called countUniqueValues(pointers pattern) (0) | 2022.04.29 |
---|---|
Write a function called sumZero which accepts a sorted array of integers. (0) | 2022.04.29 |
retrun true if every value in the array has its corresponding value squared in the secone array. (0) | 2022.04.29 |
Counting Duplicates (0) | 2022.01.29 |
Backspaces in string (0) | 2022.01.29 |