JavaScript Coding Assessment: Map, Set & Promises
Map Questions
1. Count frequency of characters using Map
// Input: "hello"
// Output: { h: 1, e: 1, l: 2, o: 1 }
2. Find first non-repeating character
// Input: "aabbccde"
// Output: "d"
3. Group anagrams using Map
// Input: ["eat", "tea", "tan", "ate", "nat", "bat"]
// Output: [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]
4. Check if two strings are isomorphic
// Input: s = "egg", t = "add"
// Output: true
Set Questions
1. Remove duplicates from an array
// Input: [1,2,2,3,4,4]
// Output: [1,2,3,4]
2. Check if two arrays have any common elements
// Input: [1,2,3], [3,4,5]
// Output: true
3. Find the intersection of two arrays
// Input: [1,2,2,1], [2,2]
// Output: [2]
4. Find the first repeating element in an array
// Input: [5, 1, 2, 3, 2, 4]
// Output: 2
Promises & Async/Await Questions
1. Create a promise that resolves after 2 seconds
// Output: "Resolved after 2s"
2. Convert a callback-based function to a Promise-based function
3. Chain multiple promises to fetch user and profile data
// Simulate async functions like getUser -> getProfile(userId)
4. Use [Link] to fetch data in parallel
// Fetch data from multiple APIs simultaneously
5. Write an async function that handles errors using try/catch
Mixed Challenge
1. Given an array of URLs, write a function to fetch all URLs using
async/await
// and return results in the same order as input
2. Given an array of student scores, return a map of score =>
frequency
// Input: [85, 90, 85, 92, 90]
// Output: Map { 85 => 2, 90 => 2, 92 => 1 }