Skip to content

Instantly share code, notes, and snippets.

View crcarrick's full-sized avatar

Chris Carrick crcarrick

View GitHub Profile
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@crcarrick
crcarrick / flatten().js
Last active August 29, 2015 14:20
Function to flatten any array, no matter how many dimensions it has. I came up with it messing around after I got stumped on a test question re: flattening multi-dimensional arrays.
function flatten (arr) {
// create a property on the function object that acts as a
// 'static'-ish variable array to hold the output
// and another for the length of the original array (you'll see why later)
// this is pretty clever and not my idea but
flatten.output = flatten.output || [];
flatten.origLength = flatten.origLength || arr.length;
// loop over array
for (var i = 0; i < arr.length; i++) {
// if arr[i] is itself an array