Show Menu
Cheatography

Statistic - Javascript Cheatsheet by

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 = ['dog', 'cat', 'bird'];

let also = new Array(5);
`

Adding Element
array[3] = 'stati­­st­ics';


Setting Value
array[3] = 'whale';


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(­­'d­og');
 

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­(­'­age', 18);

Setting a value
dict.s­­et­(­'­hei­ght', 183);

Removing a key
dict.r­­em­o­v­e(­­'he­ight');

Checking if a key is included
dict.h­­as­K­e­y(­­'fa­ge');

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. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.