Complete the code to create an empty hash map in JavaScript.
const map = [1];In JavaScript, an empty hash map can be created using an empty object literal {}.
Complete the code to find the index of value 5 in an array.
const index = arr.[1](5);
find which returns the element, not index.includes which returns true/false.The indexOf method returns the index of the first occurrence of a value in an array.
Fix the error in the linked list search function to return true if value is found.
function searchLinkedList(head, val) {
let current = head;
while (current !== null) {
if (current.value === [1]) {
return true;
}
current = current.next;
}
return false;
}value which is undefined.val.value which is incorrect.The function should compare current.value with the input val to check for equality.
Fill both blanks to create a hash map from an array of keys with initial value 0.
const keys = ['a', 'b', 'c']; const map = {}; for (let i = 0; i [1] keys.length; i++) { map[keys[i]] = [2]; }
The loop should run while i < keys.length and assign 0 as the initial value for each key.
Fill all three blanks to filter an array for values greater than 10 and create a map with those values as keys and true as values.
const arr = [5, 12, 8, 20]; const filteredMap = {}; for (let i = 0; i [1] arr.length; i++) { if (arr[i] [2] 10) { filteredMap[arr[i]] = [3]; } }
The loop runs while i < arr.length. The condition checks if arr[i] > 10. If true, it sets filteredMap[arr[i]] = true.
