Skip to content

Instantly share code, notes, and snippets.

View stefanosala's full-sized avatar
👋

Stefano Sala stefanosala

👋
View GitHub Profile
/* Final Refactor */
// This is the final form of the function. I included the first iteration below to show my thought process as well as how the code was refactored
function flatten (arr) {
if (!Array.isArray(arr)) return -1;
return arr.reduce((p, c) => !Array.isArray(c) ? p.concat(c) : p.concat(flatten(c)), []);
}
/* End Final Refactor */
/* First Iteration - With Comments */
@tobiamos
tobiamos / array-flatten.js
Last active October 20, 2018 15:43
Flatten a nested array in javascript
/* This function will flatten an array of arbitrarily nested
arrays of integers into a flat array of integers
it returns an array of flattened items
SETUP INSTRUCTIONS
make sure you have nodejs >= V6.0 installed
in your terminal make a new folder with mkdir flatten
navigate to the newly created folder with cd flatten
make a new file with touch index.js
install mocha and chai using npm install mocha chai
@dbu
dbu / Vagrantfile
Created November 13, 2012 09:26
vagrant setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
this_dir = File.dirname(__FILE__) + "/"
require this_dir + "vagrant/hostmaster.rb"
Vagrant::Config.run do |config|
# define some colors for our output
def colorize(text, color_code) "#{color_code}#{text}\033[0m" end
@Ocramius
Ocramius / Rand.php
Created April 14, 2011 13:23
MySQL RAND() function in Doctrine2 DQL
<?php
namespace My\Custom\Doctrine2\Function;
/**
* RandFunction ::= "RAND" "(" ")"
*/
class Rand extends FunctionNode
{
public function parse(\Doctrine\ORM\Query\Parser $parser)