Skip to content

Instantly share code, notes, and snippets.

@bjkeller
bjkeller / simplehashtable.js
Created March 25, 2014 18:44
Beginning of simple hash table in JS for workshopping. Uses higher-order function that creates a hash code function on Juliene Walker's jsw_hash.
var SimpleHashTable = function(hashCode) {
var table = [];
var Constructor = function() { };
Constructor.prototype.add = function(opts) {
};
return new Constructor();
}
module.exports.SimpleHashTable = SimpleHashTable;
@rochoa
rochoa / algorithms.js_vs_native_sort.md
Last active August 29, 2015 14:05
native sort vs algorithms quicksort in different node versions

Check the conversation here https://twitter.com/felipernb/status/499661739244281859

As Felipe mentions native sort covers many edge cases so native method is less performant. However I get totally different results using node.js in different versions, check results_node_* files.

Some edge cases, see tests.js file:

  • Sorting [1, null] produces different result in native than in algorithms.js.
  • ['a', null, 'a'] produces inconsistent results in algorithms.js.
@kevincennis
kevincennis / EventEmitter.js
Last active August 29, 2015 14:14
EventEmitter
var EventEmitter = (function() {
var cache = new WeakMap();
function EventEmitter() {
cache.set( this, {} );
}
EventEmitter.prototype = {
@tjunghans
tjunghans / frontend-developer-interview-questions.md
Last active October 3, 2015 23:10
Frontend Developer Interview Questions

Frontend Developer Interview Questions

JavaScript

Types

  • What are the primitive/native types exist?
  • Which built-in prototypes exist?
  • What is the difference between a primitive and complex type?
  • Which primitives have corresponding objects?
@rain1024
rain1024 / graph.md
Last active October 4, 2015 00:25
algorithm

Graph Search Algorithm

Shortest Path Problem [1]

image

Algorithms

  • Dijkstra's algorithm solves the single-source shortest path problem.
  • Bellman–Ford algorithm solves the single-source problem if edge weights may be negative.
  • A* search algorithm solves for single pair shortest path using heuristics to try to speed up the search.
  • Floyd–Warshall algorithm solves all pairs shortest paths.
@egrueter-dev
egrueter-dev / new_gist_file.md
Created March 25, 2015 14:25
Ray's Algorithms and Interview Questions Cheat Sheet!

ALGORITHMS AND INTERVIEW QUESTIONS CHEAT SHEET

DATA STRUCTURES

A data structure is a group of data organized in the computer's memory by certain specific rules defining predictable relationships between the data. Arrays, hashes and relational databases are all examples of data structures.

@eriksjaastad
eriksjaastad / Codility-js.md
Last active October 4, 2015 00:41
Codility algorithm solutions in JavaScript with better examples of the questions

###Time Complexity O(1) is constant time, no matter how much data there is, it will take the same amount of time to find the answer
O(log n) is cutting the search area in half each time
O(n) is looping through each item once
O(n2) is looping through twice
0(nn) is looping through each value and having to do something with each value based on how many values came before it
####TapeEquilibrium rewrite
A is an Array = [3,1,2,4,3]
N is the length of A

@GoSteven
GoSteven / algorithm_and_data_structure.md
Created June 23, 2012 11:48
algorithm and data structure

ant colony

Thus, when one ant finds a good (i.e., short) path from the colony to a food source, other ants are more likely to follow that path, and positive feedback eventually leads all the ants following a single path. The idea of the ant colony algorithm is to mimic this behavior with "simulated ants" walking around the graph representing the problem to solve.


List of algorithms

@riovv
riovv / array_inversion.js
Created August 24, 2012 15:00
Unreadable Array inversion counter!
/*
* Count inversions in an array using JavaScript
* Friday fun writing algorithms as UNREADABLE CODE WITH FEW LINEZ FTW :D::D
*/
var array_inversions = function (A) {
var I = 0,
R = function (A) { return (A.length < 2) ? A : M(R(A.splice(0, A.length/2)), R(A)) },
M = function (B, C) {
var D = []
@magic003
magic003 / Algorithm Tips.md
Last active December 30, 2015 18:09
This gist lists the things important for preparing a technical interview.
  • Consider using HashMap when comparing two strings or arrays.
  • When handling string problems, ask if it is ASCII. Use an array of length 256 if it is.
  • When comparing two strings or arrays, sort them first.
  • Using StringBuffer for the temporary result for string concatenate.
  • Prepend a dummy node for linked list problems.
  • Remember integer might be negative!
  • Computer cannot accurately represent float/double, use epsilon for equality check.

Common tricks:

  • Interval intersection: 1) sort by start point, binary search the end point 2) sort both start and end points, go through the array, for start point i++, for end point i--.