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 dateHandler = ({date = new Date(), days = 0, months = 0} = {}) => { | |
let copy = new Date(Number(date)); | |
copy.setMonth(months > 0 ? copy.getMonth() + months : copy.getMonth() - Math.abs(months) ) | |
copy = days > 0 ? copy.setDate(date.getDate() + days) : copy.setDate(date.getDate() - Math.abs(days)); | |
return new Date(copy) | |
} | |
const daysInAMonth = (date = new Date()) => { | |
return new Date(date.getFullYear(), date.getMonth()+1, 0).getDate(); | |
} |
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 objCreator = (key, value) => { | |
return { [key] : value}; | |
} | |
let person = objCreator('name', 'Carlos Papacidero'); | |
// resultado | |
{ | |
name: 'Carlos Papacidero' | |
} |
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 handleLoading = (area) => { | |
return { [area]: true } | |
} | |
handleLoading('header'); |
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 handleLoading = (area) => { | |
return { area: true }; | |
} | |
const loading = handleLoading('header'); // Pense um pouco e adivinhe o que irá acontecer com o objeto? | |
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 loading = { | |
header: false, | |
content: false, | |
footer: false, | |
}; |
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
// Sem Named Parameters | |
const formatarData = (dia, mes, ano, formato) => { | |
return `${ | |
formato | |
.replace('dia', dia) | |
.replace('mes', mes) | |
.replace('ano', ano) | |
}` | |
} |
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
// Utilizando Named Parameters com Default values | |
const formatarData = ({dia = 1, mes = 1, ano = 1970, formato = 'dia/mes/ano'} = {}) => { | |
return `${ | |
formato | |
.replace('dia', dia) | |
.replace('mes', mes) | |
.replace('ano', ano) | |
}` | |
} |
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
// Utilizando Named Parameters | |
const formatarData = ({dia, mes, ano, formato} = {}) => { | |
return `${ | |
formato | |
.replace('dia', dia) | |
.replace('mes', mes) | |
.replace('ano', ano) | |
}` | |
} |
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 randomNumber = ({min = 1, max = 100} = {})=> { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} | |
const gerarJogos = ({jogos = 1, dezenas = 6} = {}) => { | |
return Array.from({length: jogos}, () => { | |
const gerarNumeros = () => new Set(Array.from({length: dezenas}, () => randomNumber({min: 1, max: 60}))); | |
let game = gerarNumeros() | |
while(game.size < dezenas) game = gerarNumeros(); | |
return Array.from(game).sort((a,b)=> a -b); |
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 randomNumber = ({min = 1, max = 100} = {})=> { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
randomNumber({min: 1, max: 60}); |
NewerOlder