This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Persona(){ | |
var nome = "jimmy"; | |
var getNome = function(){ | |
console.log('nome: '+nome) | |
} | |
getNome() | |
return getNome | |
} | |
var a = Persona(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" }} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const layoutDefState = { | |
isEditorExpanded: false, | |
direction:"horizontal" | |
} | |
function layout(state=layoutDefState, action) { | |
switch (action.type){ | |
case ACT.LAYOUT_TOOGLE_EDITOR_EXPANDED: | |
return { | |
…state, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const toogleEditorExpanded = () => { | |
return { | |
type:ACT.LAYOUT_TOOGLE_EDITOR_EXPANDED, | |
} | |
} | |
export const toogleLayoutDirection => { | |
return { | |
type: ACT.LAYOUT_TOOGLE_DIRECTION | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const layoutDefState = { | |
isEditorExpanded: false, | |
direction:"horizontal" | |
} | |
const layout = createBasicReducer(‘LAYOUT’,layoutDefState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createLayoutAction = createUpdateStateAction(‘LAYOUT’); | |
const getLayoutState = getReducerState(store, ‘LAYOUT’) | |
export const toogleEditorExpanded = () => { | |
const isEditorExpanded = !getLayoutState().isEditorExpanded; | |
return updateLayoutState({ | |
isEditorExpanded | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createReducer(initialState, handlers) { | |
return function reducer(state = initialState, action) { | |
if (handlers.hasOwnProperty(action.type)) { | |
return handlers[action.type](state, action) | |
} | |
else { | |
return state | |
} | |
} | |
} |
OlderNewer