Skip to content

Instantly share code, notes, and snippets.

View jurgob's full-sized avatar

Jurgo Boemo jurgob

View GitHub Profile
function Persona(){
var nome = "jimmy";
var getNome = function(){
console.log('nome: '+nome)
}
getNome()
return getNome
}
var a = Persona();
@jurgob
jurgob / 0_reuse_code.js
Last active August 29, 2015 14:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
function unwind(arr, expandProp,renameProp){
'use strict';
return arr
.map((el) => {
return el[expandProp]
.map((subProp) => {
var subEl = Object.assign({},el,{[renameProp]:subProp});
delete subEl[expandProp];
return subEl;
@jurgob
jurgob / margeArrays.js
Last active February 22, 2016 10:00
merge 2 arrays using a custom compare function
function margeArrays(arr1,arr2,mergeFunc){
let arr2Temp = [...arr2];
const arrayMerged = arr1
.map((t) => {
const t1 = arr2Temp.filter((el,idx) => mergeFunc(t,el) && arr2Temp.splice(idx, 1) )[0]
return t1 ? t1 : t
})
.concat(arr2Temp);
return arrayMerged;
}
@jurgob
jurgob / mapFilter.js
Created February 19, 2016 17:18
mapFilter array
const mapFilter = (curArray, filterCb, callback) => curArray.map((el, idx) => filterCb(el,idx) ? callback(el,idx) : el )
const testArray = [
{friends:10, status:"happy"},
{friends:0, status:"happy"},
{friends:20, status:"happy"},
{friends:0, status:"happy"},
{friends:30, status:"super happy"}
];
const res = mapFilter(testArray, (el) => (el.friends ===0) , (el) => { return {...el, status:"forever alone!" }} )
@jurgob
jurgob / reducers.js
Created March 17, 2016 20:11
redux-utils - reducer without utils
const layoutDefState = {
isEditorExpanded: false,
direction:"horizontal"
}
function layout(state=layoutDefState, action) {
switch (action.type){
case ACT.LAYOUT_TOOGLE_EDITOR_EXPANDED:
return {
…state,
@jurgob
jurgob / actions.js
Created March 19, 2016 00:20
redux-utils - actions without utils
export const toogleEditorExpanded = () => {
return {
type:ACT.LAYOUT_TOOGLE_EDITOR_EXPANDED,
}
}
export const toogleLayoutDirection => {
return {
type: ACT.LAYOUT_TOOGLE_DIRECTION
}
@jurgob
jurgob / reducers.utils.js
Created March 19, 2016 00:22
react utils - recucers with utils
const layoutDefState = {
isEditorExpanded: false,
direction:"horizontal"
}
const layout = createBasicReducer(‘LAYOUT’,layoutDefState)
@jurgob
jurgob / actions.utils.js
Last active March 19, 2016 00:25
react utils - actions with utils
const createLayoutAction = createUpdateStateAction(‘LAYOUT’);
const getLayoutState = getReducerState(store, ‘LAYOUT’)
export const toogleEditorExpanded = () => {
const isEditorExpanded = !getLayoutState().isEditorExpanded;
return updateLayoutState({
isEditorExpanded
})
}
@jurgob
jurgob / reduxUtils.js
Last active March 19, 2016 00:29
react utils - the utils
function createReducer(initialState, handlers) {
return function reducer(state = initialState, action) {
if (handlers.hasOwnProperty(action.type)) {
return handlers[action.type](state, action)
}
else {
return state
}
}
}