One Stop Frontend Interview Questions (Preview)
One Stop Frontend Interview Questions (Preview)
js
03. Implement Currying - Easy
w.
//// Asked in Intuit, Tekion, Adobe, MakeMyTrip, Jio, Paytm
js
//// Asked in Zepto
w.
//// Asked in Yandex
js
27. Implement Custom String Tokenizer - Medium
w.
28. Implement Custom setTimeout - Medium
//// Asked in Swiggy, Disney+ Hotstar
js
39. Implement Custom Object.is() method - Easy
w.
40. Implement Custom lodash _.partial() - Medium
//// Asked in Meesho
js
52. Implement Custom Virtual DOM - II (Deserialize) - Medium
//// Asked in Meta
w.
53. Implement Memoize/Cache identical API calls - Hard
//// Asked in Facebook
e
r vi
te
In
Throttling Promises by Batching
Problem Statement
Scenario
Now, assume each of the function calls make an API call and
return a promise which either resolves/rejects. If you have a
scenario you need to make 50 API calls concurrently. It would
be a bad practice since we’re overloading the server by
making 50 API calls instantly.
throttlePromises(listOfAPIsToCall, 5)
.then(data => {
// data - If all the API calls processed in batches succeeds
})
.catch(error => {
// error - If any of the API call fails
})
Implementation
Test Cases
// ---------------------------------------
throttlePromises(input1, 3)
.then(data => console.log('Resolved with', data))
.catch(error => console.log('Rejected with', error))
// Resolved with [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
// ---------------------------------------
throttlePromises(input2, 4)
.then(data => console.log('Resolved with', data))
.catch(error => console.log('Rejected with', error))
// Rejected with 6
Problem Statement
// Syntax
function get(obj, path, defaultValue) {}
Example
const obj = {
a: {
b: 'Hello',
c: null,
Implementation
return defaultValue;
}
}
Test Cases
const obj = {
a: {
b: 'Hello',
c: null,
d: [1, 2, 'World'],
e: [
{ name: 'Peter Parker' },
{ work: 'Spiderman' }
],
h: {
i: {
j: 'Iron Man',
Problem Statement
And you should not use the built-in function directly for the
problem, instead write your own version.
// Syntax
Example
myClearTimeout(id);
// Note : The time `4001 ms` is not equal to the delay=4000 we
passed. This is because by design, setTimeout only guarantees to
execute "after" specified delay, but doesn't guarantee that it
will execute exactly at delay=4000. So don't expect timer to be
executed exactly at the specified `delay`
Implementation
function createMySetTimeout() {
// this unique `timerID` helps to identify the
registered/scheduled timer
let timerID = 0;
// `timerMap` which maintains all the unique identifiers `id`
for the timer scheduled/registered
const timerMap = {};
function myClearTimeout(id) {
// If a timer is registered/scheduled for the `id` -
delete it
if (timerMap[id]) delete timerMap[id];
}
function scheduleTimer() {
// create unique id
return id;
}
Test Cases