0% found this document useful (0 votes)
8 views3 pages

JavaScript DSA CheatSheet

This document is a cheat sheet for JavaScript data structures and algorithms (DSA), covering essential array methods, looping techniques, object manipulation, sets, linked lists, stacks, queues, tree nodes, recursion patterns, and binary search implementation. It provides concise code snippets for each concept, making it a quick reference guide for developers. The content is structured to facilitate easy understanding and application of common DSA principles in JavaScript.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

JavaScript DSA CheatSheet

This document is a cheat sheet for JavaScript data structures and algorithms (DSA), covering essential array methods, looping techniques, object manipulation, sets, linked lists, stacks, queues, tree nodes, recursion patterns, and binary search implementation. It provides concise code snippets for each concept, making it a quick reference guide for developers. The content is structured to facilitate easy understanding and application of common DSA principles in JavaScript.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JavaScript DSA Cheat Sheet

Array Methods
[Link](x); // Add to end

[Link](); // Remove from end

[Link](); // Remove from front

[Link](x); // Add to front

[Link](i, j); // Copy from i to j-1

[Link](i, 1); // Remove at index

[Link](x); // Check existence

[Link](x); // Find index

Looping Tricks
for (let i = 0; i < [Link]; i++) { ... }

[Link](x => [Link](x));

[Link](x => x * 2);

[Link](x => x > 0);

[Link]((acc, val) => acc + val, 0);

Objects (as Hash Maps)


let map = {};

map["key"] = 42;

if ("key" in map) { ... }

[Link](map).forEach(k => [Link](map[k]));

Sets
let set = new Set([1, 2, 3]);

[Link](2); // true

[Link](4); // add

[Link](1); // remove

Linked List Node


class Node {
constructor(val) {

[Link] = val;

[Link] = null;

Stack & Queue


// Stack

let stack = [];

[Link](1);

[Link]();

// Queue using array

let queue = [];

[Link](1); // enqueue

[Link](); // dequeue

Tree Node
class TreeNode {

constructor(val) {

[Link] = val;

[Link] = null;

[Link] = null;

Recursion Pattern
function factorial(n) {

if (n <= 1) return 1;

return n * factorial(n - 1);

}
Binary Search
function binarySearch(arr, target) {

let left = 0, right = [Link] - 1;

while (left <= right) {

let mid = [Link]((left + right) / 2);

if (arr[mid] === target) return mid;

else if (arr[mid] < target) left = mid + 1;

else right = mid - 1;

return -1;

You might also like