Cheatography
https://cheatography.com
Cheat sheet for statistics homeworks
Array
Declaration and initialization
let array = ['cat', 'dog', 'fish'];
let array2 = new Array(3);
Adding an element
array[3] = 'dog';
Setting a value
array[1] = 'cat';
Deleting an element
delete array[3];
Looping
array.forEach(function(item) {
console.log(item);
}
Checking existence of a value
array.include('cat');
|
Dictionary
Creation
let dict = new Dictionary();
Adding an key-value pair
dict.add('cat', 10);
Setting a value for a key
dict.set('percentage', 5.10);
Removing a key
dict.remove('percentage');
Checking existence of a key
dict.hasKey('frequency');
Checking existence of a value
dict.hasValue(10);
|
HashSet
Creation
let hashset = new HashSet();
Adding an element
hashset.add(1);
Removing an element
hashset.delete(1);
Checking the existence of an element
hashset.has(3);
Looping
let keys = hashset.values();
for(let i = 0; i < keys.length; i++){
console.log(keys[i]);
}
|
|
|
List
Creation
const list = new List();
Adding an element
list.add(1);
list.addAtHead(0);
Removing an element
list.remove(2);
Setting a value
list.set(0, 251);
Checking existence of a value
list.contains(1);
Looping
for(let i = 0; i < list.size(); i++){
console.log(list.get(i));
}
|
Stack
Creation
let stack = new Stack();
Adding an element
stack.push(1);
Fetching top of stack
stack.peek();
Removing an element
stack.pop();
|
SortedSet
Creation
let sortedSet = new SortedSet();
Adding an element
sortedSet.add(3);
Removing an element
sortedSet.delete(3);
Checking the existence of an element
sortedSet.has(1);
Looping
for(element in sortedSet.toArray) {
console.log(element);
}
|
|
|
Queue
Creation
let queue = new Queue();
Adding an element
queue.enqueue(1);
Fetch of the first element
queue.front();
Removing an element
queue.dequeue();
Checking the existence of an element
queue.contains(7);
|
LinkedList
Creation
let linkedList = new LinkedList();
Adding an element
linkedList.append(1);
linkedList.prepend(1);
linkedList.addAt(1, 1);
Fetch of the head value
linkedList.fetchHead();
Get the value of a node
linkedList.getAt(1);
Removing an element
linkedList.removeAt(1);
linkedList.delete(1);
Check existence of a value
linkedList.contains(1);
Looping
for (const e of linkedList) {
console.log(e);
}
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets