Skip to content

Instantly share code, notes, and snippets.

View chrisasmith's full-sized avatar

Christopher Smith chrisasmith

View GitHub Profile
@chrisasmith
chrisasmith / Smashing Arrays
Created September 7, 2016 20:13
Smashing compound arrays [1, [2,3], [4,[5]], 6, 7, [8, [9], 10]]
function smash(array) {
var smashedArr = [];
//in this loop, "block" is the first ele of the array
// condition - checks that block is not undefiend/end of array
for (var block = array.shift(); block !== undefined; block = array.shift()) {
//check true
switch(true){
//that the given "block" is an array
case (Array.isArray(block)):
//TRUE -- add the block to the front of the array
@chrisasmith
chrisasmith / node_tutorial.md
Created February 5, 2017 16:28 — forked from nlaz/node_tutorial.md
Build a Backend from Scratch
@chrisasmith
chrisasmith / CopyArrayOfObjects.js
Last active February 20, 2017 23:10
Make a copy of an Array then check for objects. If object is found, make a COPY of that object not a reference to the original object.
(function () {
var defaultArr = [1, {
obj_a: 1
},
[4, [{
obj_c: 'object value'
}]], 6, 7, [8, {
obj_b: 2
}, {
obj_d: 1977
@chrisasmith
chrisasmith / Unique-ifiedArrayOfObjects.js
Created February 23, 2017 23:47
Take an array of objects and return a unique-ified version of the same array.
Array.prototype.getUnique = function() {
var base = this;
var arr = [];
for (var i = 0; i < base.length; i++) {
for (var j = i + 1; j < base.length; j++) {
if (base[i] === base[j]) {
j = ++i;
}
}
arr.push(base[i]);