Skip to content

Instantly share code, notes, and snippets.

🤓
coding

Daniel Leite de Oliveira dleitee

🤓
coding
Block or report user

Report or block dleitee

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dleitee
dleitee / immutable.functions.js
Created Apr 27, 2017
Creating immutable functions
View immutable.functions.js
// Example using Objects.assign
const changeName = (user, newName) => Object.assign({}, user, {
name: newName
})
// Example using destructuring assignment
const changeName = (user, newName) => ({
...user,
name: newName,
})
View immutable.js
const user = {
name: 'John Due',
birthdate: '1988-08-15',
}
const changeName = (user, newName) => {
return {
...user, // destructuring user object
name: newName, // override name attribute with new name
}
View mutable.js
const user = {
name: 'John Due',
birthdate: '1988-08-15',
}
const changeName = (user, newName) => {
const newUser = user
newUser.name = newName
return newUser
}
View object.assign.js
// Example using Objects.assign
const deposit = (account, value) => Object.assign({}, account, {
balance: account.balance + value
})
View object.destructuring.js
// Example using destructuring assignment
const deposit = (account, value) => ({
...account,
balance: account.balance + value,
})
View deposit.js
const account = {
balance: 1000,
bank: '',
number: '',
}
const deposit = (account, value) => {
const newAccount = account
newAccount.balance = account.balance + value
return newAccount
View deposit.js
const account = {
balance: 1000,
bank: '',
number: '',
}
const deposit = (account, value) => {
return {
...account,
balance: account.balance + value,
View avatar.css
.avatar-size {
max-width: 70px;
max-height: 70px;
height: 70px;
width: auto;
object-fit: cover;
}
View git-alias.md
git config --global alias.co checkout 
git config --global alias.br branch 
git config --global alias.ci commit 
git config --global alias.st status
git config --global color.ui auto
You can’t perform that action at this time.