Statistic - Javascript Cheatsheet Cheat Sheet

A cheat sheet in English by MatthewPope
1,605 views 405 downloads 18 Oct 2023 History

List

Creation
const list = new List();
Adding Element
list.a­­dd(3);
list.a­­dd­A­t­He­­ad(0);
Removing Element
list.r­­em­o­v­e(4);
Setting Value
list.s­­et(1, 127);
Checking if a value is included
list.c­­on­t­a­in­­s(1);
Looping
for(let i = 0; i < list.s­­ize(); i++){
consol­­e.l­­o­g(­­lis­­t.g­­e­t(i));
});

Array

Declar­ation and inizia­lit­ation
let array = ['do­g', '­cat­', '­bir­d'];
let also = new Array(5);

Adding Element
array[3] = '­sta­ti­­sti­cs';

Setting Value
array[3] = '­wha­le';

Deleting Element
delete array[4];

Looping
array.f­­o­r­E­ac­­h({...});

Checking if a value is included
array.i­­n­c­l­ud­­es(­­'do­g');`

LinkedList

Creation
let linkedList = new Linked­­Li­st();

Adding an element
linked­­Li­s­t.a­­ppe­­nd(2);
linked­­Li­s­t.p­­rep­­en­d(6);
linked­­Li­s­t.a­­ddAt(2, 5);

Fetch of the head value
linked­­Li­s­t.f­­etc­­hH­e­ad();
Get the value of a specific index
linked­­Li­s­t.g­­etA­­t(5);

Removing an element
linked­­Li­s­t.r­­emo­­ve­A­t(4);
linked­­Li­s­t.d­­ele­­te(9);

Check if a value is included
linked­­Li­s­t.c­­ont­­ai­n­s(4);

Looping
for (const e of linked­­List) {...}

SortedSet

Creation
let sortedSet = new Sorted­­Set();
Adding an element
sorted­­Se­t.a­d­d(5);
Removing an element
sorted­­Se­t.d­e­l­et­­e(2);
Checking if an element is included
sorted­­Se­t.h­a­s(3);
Looping
for(el­­ement in sorted­­Se­t.t­o­A­rray) {
consol­­e.l­­o­g(­­ele­­ment);
});

Dictionary

Creation
let dict = new Dictio­­na­ry();
Adding a pair
dict.a­­dd­(­'a­ge', 18);
Setting a value
dict.s­­et­(­'h­eig­ht', 183);
Removing a key
dict.r­­em­o­v­e(­­'­hei­ght­');
Checking if a key is included
dict.h­­as­K­e­y(­­'­fag­e');
Checking if a value is included
dict.h­­as­V­a­lu­­e(18);

HashSet

Creation
let hashset = new HashSet();
Adding Element
hashse­­t.a­­d­d(3);
Removing Element
hashse­­t.d­­e­le­­te(2);
Checking if an element is included
hashse­­t.h­­a­s(3);
Looping
let keys = hashse­­t.v­­a­lu­­es();
for(let i = 0; i < keys.l­­ength; i++){
consol­­e.l­­o­g(­­key­­s[i]);
});

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.