Technical Question: How much experience do you have with Node.js? Afterwards, they challenge you with finding the bugs in a Node.js coding problem.
Expected Output: [Charlie, Eve]
Starting Output: Promise {[ ]} or error
------------------------------------------------------------------------
const previousEmployees = () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve([
{ id: 1, name: 'Charlie' },
{ id: 2, name: 'David' },
{ id: 3, name: 'Eve' }
]);
}, 200);
});
};
const currentEmployees = () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve([
{ id: 1, name: 'Charlie' },
{ id: 2, name: 'Ava' },
{ id: 3, name: 'Eve' },
{ id: 4, name: 'Bob' },
{ id: 5, name: 'Nina' }
]);
}, 200);
});
};
// Asynchronous Function: GetAllExistingEmployees()
const GetAllExistingEmployees = () => {
let previousList = previousEmployees().list; // ❌ wrong, .list doesn't exist
let currentList = currentEmployees().list; // ❌ same
let result = [];
for (let i = 0; i < currentEmployees; i++) { // ❌ wrong: comparing function to number
for (let j = 0; j < previousEmployees; j++) {
if (currentList[i] === previousList[j]) { // ❌ comparing objects by reference
result.push(currentList[i].name);
}
}
}
return result;
};
console.log(GetAllExistingEmployees()); // ❌ Output: Promise { [] } or error