This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function countLetters(str) { | |
| const smallString = str.toLowerCase(); | |
| const obj = {}; | |
| for (let i = 0; i < smallString.length; i++) { | |
| if (obj[smallString[i]]) { | |
| obj[smallString[i]] += 1; | |
| } else { | |
| obj[smallString[i]] = 1; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Hash Method: | |
| function twoSum(nums, target) { | |
| const map = new Map(); // Stores value -> index | |
| for (let i = 0; i < nums.length; i++) { | |
| const complement = target - nums[i]; | |
| if (map.has(complement)) { | |
| return [map.get(complement), i]; // Found the two indices |