Ui22cs59lab6 We
Ui22cs59lab6 We
Aim:- 1. Implement a debounce function in JavaScript that limits the frequency of a function’s execution
when it’s called repeatedly within a specified time frame.
2. Write a function that takes an array of objects and a key, and returns a new array sorted based on the
values of that key in ascending order.
3. Implement a deep clone function in JavaScript that creates a copy of a nested object or array without
any reference to the original.
4. Implement a function that takes two sorted arrays and merges them into a single sorted array without
using any built-in sorting functions.
Code :-
// 1. Debounce function
let timer;
clearTimeout(timer);
};
}
logMessage("Hello, World!");
return 0;
});
const objectsArray = [
];
console.log(sortByKey(objectsArray, "id"));
function deepClone(obj) {
return obj;
if (Array.isArray(obj)) {
if (obj.hasOwnProperty(key)) {
clonedObj[key] = deepClone(obj[key]);
return clonedObj;
console.log(clonedObject);
let i = 0, j = 0;
mergedArray.push(arr1[i]);
i++;
} else {
mergedArray.push(arr2[j]);
j++;
}
while (i < arr1.length) {
mergedArray.push(arr1[i]);
i++;
mergedArray.push(arr2[j]);
j++;
return mergedArray;
Output :-
Conclusion :- In this lab, we successfully implemented and tested four essential JavaScript functions:
debounce, sorting by key, deep cloning, and merging sorted arrays. These functions demonstrate practical
applications of closures, recursion, and algorithmic problem-solving. By completing this, we reinforced
key programming concepts and their real-world utility.