Created
October 15, 2024 17:06
-
-
Save srsajjad/fe808ccd9ffa51fd909921f0ee3ba0e7 to your computer and use it in GitHub Desktop.
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
// first | |
const moveZeros = (nums) => { | |
// const nums = [0,1,0,3,12] | |
return nums; | |
}; | |
// second - done | |
const intersectionOfTwoArrays = (nums1, nums2) => { | |
const set1 = new Set(nums1); | |
const set2 = new Set(nums2); | |
return [...set1].filter((each) => set2.has(each)); | |
}; | |
// third - done | |
const findFirstUniqueCharacterInAString = (s) => { | |
const map = {}; | |
for (i in s) { | |
const currentChar = s[i].toLowerCase(); | |
map[currentChar] = (map[currentChar] || 0) + 1; | |
} | |
for (i = 0; i < s.length; i++) { | |
const currentChar = s[i].toLowerCase(); | |
if (map[currentChar] === 1) return i; | |
} | |
return -1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment