Skip to content

Instantly share code, notes, and snippets.

Gregg GreggSetzer

  • USA
Block or report user

Report or block GreggSetzer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@GreggSetzer
GreggSetzer / ip.txt
Created Aug 29, 2018
Retrieve your local IP address at Mac Command LIne
View ip.txt
alias ip='ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2'
@GreggSetzer
GreggSetzer / tree.js
Last active Jul 27, 2018
JavaScript Interview Question: Tree
View tree.js
class Node {
constructor(data) {
this.data = data;
this.children = [];
}
add(data) {
this.children.push(new Node(data));
}
@GreggSetzer
GreggSetzer / find-largest-integer-in-array.js
Created Jul 16, 2018
JavaScript Interview Question: Largest integer in array?
View find-largest-integer-in-array.js
/*
Return the largest value in an array of non-negative integers
*/
function largestInt(arr) {
if (arr.length === 0) {
return -1;
}
return arr.reduce(comparator);
@GreggSetzer
GreggSetzer / equality.js
Created Jul 16, 2018
JavaScript Interview Questions: Equality
View equality.js
/*
Write a function that determines whether two integers are equal without using any comparison operators.
Use the bitwise XOR operator.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR
Using XOR, if any of the bits are different, a 1 is returned, otherwise, a 0 is returned.
*/
function isEqual(n1, n2) {
return (n1 ^ n2) === 0;
@GreggSetzer
GreggSetzer / linked-list.js
Last active Jul 27, 2018
JavaScript Interview Question: Linked List
View linked-list.js
/*
Linked List example.
*/
/**
* Node class
* Contains two properties and no methods.
* data - The data to be stored in a single node.
* next - The reference to the next node in the chain.
*/
@GreggSetzer
GreggSetzer / queue-stack.js
Created Jun 22, 2018
JavaScript Interview Question: Create a Queue using Stacks
View queue-stack.js
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Create a Queue implementation using two stacks. Do not use an
* array inside the Queue class. Queue should implement add() and
* remove().
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class Stack {
constructor() {
this.data = [];
}
@GreggSetzer
GreggSetzer / queue.js
Last active Jun 22, 2018
JavaScript Interview Question: Queue
View queue.js
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Solve some arbitrary problem using a queue.
* The interviewer has asked to provide a solution to a problem
* using a Queue as the data structure. Using the native Array
* in JavaScript with restricted access to its full list of methods
* is one possible solution.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//Queues implement the FIFO method. First in, first out.
class Queue {
@GreggSetzer
GreggSetzer / fibonacci.js
Created Jun 22, 2018
JavaScript Interview Question: Fibonacci
View fibonacci.js
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Write a program to find a fibonacci number.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Iterative solution
// O(n) Linear Runtime Complexity
// This is an alternative approach to solving fibonacci
// without recursion. However, this shoudn't be the
// final answer in an interview setting.
@GreggSetzer
GreggSetzer / refactoring-for-loops-example-2.js
Last active Jun 20, 2018
Simplifying JavaScript code using Functional Programming
View refactoring-for-loops-example-2.js
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Given an array of orders, find the top 3 customers with the
* highest lifetime value (those that spent the most over time).
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Start with the initial implementation.
//
// One approach to solving this task would be to create
@GreggSetzer
GreggSetzer / revealing-module-pattern.js
Created Mar 2, 2018
Javascript Interview Question: Revealing Module Pattern
View revealing-module-pattern.js
/*
Use the module pattern to group together similar methods such as database services.
In the example below, the ItemDao (Data Access Object) simulates several functions
that interact with a database.
1. Use modules to encapsulate related functionality.
2. A module pattern at its core is an object literal.
3. When using the module in code, call the functions using the key/value syntax.
For example: itemDao.findOne(1);
4. Wrap the object into a function to create a closure for private variables. Examples
You can’t perform that action at this time.