Instructions
- 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
- 2. Thoroughly review each solution before proceeding to ensure full understanding.
- 3. Final results will be available after submission to provide insights into areas for further improvement.
- 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
- 5. Once submitted, responses are final, so ensure you’re confident in your answers.
- 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.
All Problems
Question
Action
What does the following function do?
What will deepSum({a: 1, b: {c: 2, d: {e: 3}}}) return?
What will countKeys({a: 1, b: {c: 2, d: {e: 3}}}) return?
Which of the following is true about recursive object traversal?
What does the following function do?
What is the time complexity of recursively traversing a deeply nested object?
How can recursion be used to modify deeply nested values in an object?
What are the key differences between recursive functions that operate on arrays versus those that operate on objects?
Why is recursion particularly useful when working with deeply nested objects?
What potential risks should you be aware of when using recursion to traverse deeply nested objects?
What does the following function do?
function findValue(obj, key) { if (obj.hasOwnProperty(key)) { return obj[key]; } for (let k in obj) { if (typeof obj[k] === "object") { let result = findValue(obj[k], key); if (result) return result; } } return null; }
What will deepSum({a: 1, b: {c: 2, d: {e: 3}}}) return?
function deepSum(obj) { let sum = 0; for (let key in obj) { if (typeof obj[key] === "number") { sum += obj[key]; } else if (typeof obj[key] === "object") { sum += deepSum(obj[key]); } } return sum; }
What will countKeys({a: 1, b: {c: 2, d: {e: 3}}}) return?
function countKeys(obj) { let count = 0; for (let key in obj) { count++; if (typeof obj[key] === "object") { count += countKeys(obj[key]); } } return count; }
Which of the following is true about recursive object traversal?
What does the following function do?
function deepCopy(obj) { let newObj = Array.isArray(obj) ? [] : {}; for (let key in obj) { if (typeof obj[key] === "object") { newObj[key] = deepCopy(obj[key]); } else { newObj[key] = obj[key]; } } return newObj; }