Member-only story
Here’s a quick JavaScript warmup for solving coding problems
No fluff, just warmup.
4 min readDec 24, 2024
Note: This is not all-inclusive, rather than just a brief overview of some key data structures, algorithms, and problem-solving strategies.
Data Structures
//Arrays
const arr = [1, 2, 3];
//Strings
const str = 'Hello, World!';
//HashMaps using Map object
const hashMap = new Map();
hashMap.set('key1', 'value1');
hashMap.set('key2', 'value2');
console.log(hashMap.get('key1')); // Output: 'value1'
console.log(hashMap.has('key3')); // Output: false
hashMap.delete('key1');
for (const [key, value] of hashMap) {
console.log(`${key}: ${value}`);
}
//HashMaps using generic object
const objHashMap = {
key1: 'value1',
key2: 'value2',
};
console.log(objHashMap['key1']); // Output: 'value1'
//Linked Lists
class ListNode {
constructor(val) {
this.val = val;
this.next = null;
}
}
//Stacks and Queues
const stack = [];
stack.push(1);
stack.pop();
const queue = [];
queue.push(1);
const item = queue.shift();
//Trees
class TreeNode {
constructor(val) {
this.val = val;
this.left = null;
this.right = null;
}
}
const root = new TreeNode(1);
root.left = new TreeNode(2);
root.right = new TreeNode(3);
Algorithms
//Binary Search
function binarySearch(arr, target) {
let left = 0;
let right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) return mid;
if (target >…