Skip to content

Instantly share code, notes, and snippets.

View jwgoedert's full-sized avatar

James Wesley Goedert jwgoedert

View GitHub Profile
@jwgoedert
jwgoedert / .block
Created May 17, 2017 03:03 — forked from arpitnarechania/.block
Condegram Spiral Plot
license: MIT
@jwgoedert
jwgoedert / jsbin.dipume.js
Last active January 30, 2017 21:16 — forked from anonymous/index.html
Last!
var myArr = [1,2,3,4,5,6,7,8,6,7,8,6];
//last with all the safeties using a for loop
last = function last(arr, number){
var newArr = [];
if(!Array.isArray(arr)){
return [];
}else if(isNaN(number) || number === undefined ){
return arr[arr.length - 1];
}else if(number < 0){
return newArr;
@jwgoedert
jwgoedert / jsbin.waporu.js
Created January 30, 2017 21:03 — forked from anonymous/index.html
Extend!
//takes any number of objects and creates one unified object.
_.extend1 = (...objects) =>{
const target = objects[0];
_.each(objects, (obj, i, objects) =>{
if(i === 0)return;
_.each(obj,( val, key, obj)=>{
target[key] = val;
});
});
@jwgoedert
jwgoedert / jsbin.meqobig.js
Created January 30, 2017 21:02 — forked from anonymous/index.html
Reduce!
/*literally does everything... takes a collection, a call-back
function and a starting state(this could be a number, )
*/
_.reduce = function(collection, fn, seed){
var prevResult = seed;
if(seed === undefined) seed = collection[0], prevResult = 1;
_.each(collection, function(el, i, collection){
prevResult = fn(prevResult, el, i);
});
return prevResult;
@jwgoedert
jwgoedert / jsbin.hoyale.js
Created January 30, 2017 21:02 — forked from anonymous/index.html
Some!
//takes a collection and returns a boolean if any of the
//values pass the test
_.some = function some(collection, fn){
var isTrue = false;
var isFalse = true;
if(_.typeOf(fn) !== 'function') fn = _.identity;//why this is?
_.each(collection, function(el, i, collection){
fn(el, i, collection) ? isTrue = true : isFalse = false;
});
if (isTrue === false) return false;
@jwgoedert
jwgoedert / jsbin.towaceq.js
Created January 30, 2017 21:01 — forked from anonymous/index.html
Every!
//takes a collection and test and returns a boolean if
//all values pass the test
_.every = (col, test) => {
if (!test) test = _.identity;
let passed = true;
_.each(col, (item, i, col) =>{
if(!test(item, i, col)) passed = false;
});
return passed
};
@jwgoedert
jwgoedert / jsbin.fodigu.js
Created January 30, 2017 21:00 — forked from anonymous/index.html
Contains!
//takes a collection and checks if it has a value in it
_.contains = function contains(collection, value){
var tOrF = false;
var valIs;
_.each(collection, function(el, i, collection){
tOrF = (el === value ? valIs = true : false);
});
if (valIs !== undefined) return valIs;
return tOrF;
}
@jwgoedert
jwgoedert / jsbin.zecaci.js
Created January 30, 2017 21:00 — forked from anonymous/index.html
Pluck!
//takes an array and property and returns an array of those values
_.pluck = function pluck(arr, property){
var values = [];
_.map(arr, function(el, i, arr){
values.push(el[property]);
});
return values;
}
@jwgoedert
jwgoedert / jsbin.vabazi.js
Last active January 30, 2017 20:59 — forked from anonymous/index.html
Map!
//takes a collection and a function with (el,i,col)
//and returns a new collections modified
_.map1 = function map(collection, fn){
var newCollection = [];
_.each(collection, function(el, i, collection){
newCollection.push(fn(el,i,collection));
});
return newCollection;
}
//steve
@jwgoedert
jwgoedert / jsbin.qeyeho.js
Created January 30, 2017 20:58 — forked from anonymous/index.html
Unique!
//takes an array and returns an array of unique values
_.unique = function unique(list){
var unArray = [];
_.each(list, function(el, i, list){
if(_.indexOf(unArray, el) === -1) unArray.push(el);
});
return unArray;
}