Skip to content

Instantly share code, notes, and snippets.

class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class Queue {
constructor() {
this.first = null;
class Stack {
constructor() {
this.list = [];
}
// Peek the top element.
peek() {
this.list.length ? console.log(this.list[this.list.length - 1]) : console.log('The stack is empty.');
return this.list.length;
}
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class Stack {
constructor() {
this.top = null;
@darshna09
darshna09 / myDoublyLinkedList.js
Created June 7, 2021 10:06
Doubly Linked List Implementation in JavaScript
class Node {
constructor(value) {
this.value = value;
this.next = null;
this.previous = null;
}
}
class DoublyLinkedList {
constructor(value) {
@darshna09
darshna09 / mySinglyLinkedList.js
Created June 4, 2021 04:49
Single Linked List Implementation in JavaScript
// Creating node
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class LinkedList {
// Empty Linked List will not be formed.
@darshna09
darshna09 / myHashTable.js
Last active November 14, 2021 17:27
Hash Table Implementation in JavaScript
class HashTable {
constructor(size) {
this.data = new Array(size);
}
// Hash Function
_hash(key) {
let hash = 0;
for(let i = 0; i < key.length; i++) {
hash = (hash + key.charCodeAt(i) * i) % this.data.length;
@darshna09
darshna09 / myHashTable_boilerplate.js
Created May 3, 2021 09:25
Boilerplate code to implement hash tables in JavaScript.
class HashTable {
constructor(size) {
this.data = new Array(size);
}
// Hash Function
_hash(key) {
let hash = 0;
for (let i = 0; i < key.length; i++) {
hash = (hash + key.charCodeAt(i) * i) % this.data.length;
@darshna09
darshna09 / isPalindrome.js
Last active April 19, 2021 09:21
Check if the given word is a palindrome or not.
/**
* @param {string} word
* @return {boolean}
* true if palindrome else false
*/
function isPalindrome (word) {
if (word) {
return word.toLowerCase() === word.toLowerCase().split('').reverse().join('') ? true : false;
} else {
return false;
// Implement Array in JavaScript
class OurArray {
constructor () {
this.length = 0;
this.data = {}; // An array in JavaScript is Object
}
/** Lookup: Time Complexity = O(1)
* @param {number} index
class OurArray {
constructor () {
this.length = 0;
this.data = {}; // An array in JavaScript is Object
}
/** Lookup: Time Complexity = O(1)
* @param {number} index
* @return {any} item
*/