Skip to content

Instantly share code, notes, and snippets.

View RomanTurner's full-sized avatar
🤫

Roman RomanTurner

🤫
View GitHub Profile
@RomanTurner
RomanTurner / Node.js
Created April 7, 2021 22:12
Node for LL
//Node
class Node {
constructor(el){
this.element = el;
this.next = null;
}
}
@RomanTurner
RomanTurner / Stack-LL.js
Last active April 7, 2021 22:18
Starting a Stack using Linked List
class Stack {
constructor(){
this.length = 0;
this.head = null;
}
@RomanTurner
RomanTurner / Push.js
Created April 7, 2021 22:21
Push in a LL for a Stack
//Push data in the stack
push = (el) => {
//Create a new node
let node = new Node(el),
current;
//Add the new node at the top
current = this.head;
node.next = current;
this.head = node;
@RomanTurner
RomanTurner / Pop.js
Created April 7, 2021 22:22
Pop on LL for Stack
//Pop the item from the stack
pop = () => {
let current = this.head;
//If there is item then remove it
//and make the next element as the first
if(current){
let el = current.element;
current = current.next;
this.head = current;
@RomanTurner
RomanTurner / Peek.js
Created April 7, 2021 22:24
Peek on LL for Stack
//Return the first element in the stack
peek = () => {
if(this.head){
return this.head.element;
}
return null;
}
@RomanTurner
RomanTurner / to-array.js
Created April 7, 2021 22:27
Turns LL into Array
//Convert the stack to an array
toArray = () => {
let arr = [];
let current = this.head;
while(current){
arr.push(current.element);
current = current.next;
}
return arr;
@RomanTurner
RomanTurner / Stack.js
Created April 7, 2021 22:30
Stack in JavaScript
class Stack {
constructor(){
this.length = 0;
this.head = null;
}
//Push data in the stack
push = (el) => {
//Create a new node
let node = new Node(el),
@RomanTurner
RomanTurner / arrayQueue.js
Created April 21, 2021 15:25
Queue in JS with array
class Queue{
constructor(...items){
//initialize the items in queue
this._items = []
// enqueuing the items passed to the constructor
this.enqueue(...items)
}
enqueue(...items){
//push items into the queue
@RomanTurner
RomanTurner / fizzbuzz.rb
Created June 27, 2021 00:59
Fizzbuzz oop ruby
# Here is how I would implement Fizzbuzz with objects
# The main issue with your class is what's called
# single responsibility principle
# classes should do one thing and be about
# instances of those classes
# the fizzbuzz class should be about the loop
# just solving fizzbuzz individually
class Fizzbuzz
attr_accessor :value