Skip to content

Instantly share code, notes, and snippets.

@srsajjad
Created October 15, 2024 17:06
Show Gist options
  • Save srsajjad/fe808ccd9ffa51fd909921f0ee3ba0e7 to your computer and use it in GitHub Desktop.
Save srsajjad/fe808ccd9ffa51fd909921f0ee3ba0e7 to your computer and use it in GitHub Desktop.
// 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