Last active
April 11, 2021 19:35
-
-
Save andreleite/ea2572659e13503bf7b1a47552a78474 to your computer and use it in GitHub Desktop.
ES6 - React
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
console.clear(); | |
var string = 'opcon4'; | |
function changeString(string) { | |
string = 'opcon1'; | |
console.log('inside', string); | |
} | |
changeString(string); | |
console.log('outside', string); |
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
console.clear(); | |
var number = 22; | |
function changeNumber(number) { | |
number = number + 20; | |
console.log('inside', number); | |
} | |
changeNumber(number); | |
console.log('outside', number); |
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
console.clear() | |
var array = [ | |
'backbone', | |
'require', | |
'gulp' | |
]; | |
function changeArray(array) { | |
array[0] = 'react'; | |
console.log('inside', array); | |
} | |
changeArray(array); | |
console.log('outside', array); |
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
console.clear(); | |
var developer = { | |
name: 'Orlando', | |
surname: 'Bustos' | |
}; | |
function changeObject(developer) { | |
developer.name = 'Don ' + developer.name; | |
console.log('inside', developer); | |
} | |
changeObject(developer); | |
console.log('outside', developer); |
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
console.clear(); | |
var x = 2; | |
function square(x) { | |
x = x * x; | |
return x; | |
} | |
var newX = square(x); | |
console.log(newX); | |
console.log( | |
'same number?', | |
x === newX | |
); |
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
console.clear() | |
var opcons = [1, 2, 3]; | |
function addOpcon(opcons) { | |
opcons.push(4); | |
return opcons; | |
} | |
var newOpcons = addOpcon(opcons); | |
console.log(newOpcons); | |
console.log( | |
'same array?', | |
opcons === newOpcons | |
); |
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
console.clear(); | |
var opcons = [1, 2, 3]; | |
function addOpcon(opcons) { | |
var newOpcons = []; | |
var i; | |
for(i = 0; i < opcons.length; i++) { | |
newOpcons[i] = opcons[i]; | |
} | |
newOpcons[i] = 4; | |
return newOpcons; | |
} | |
var newOpcons = addOpcon(opcons); | |
console.log(newOpcons); | |
console.log( | |
'same array?', | |
opcons === newOpcons | |
); |
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
console.clear() | |
var developer = { | |
name: 'Orlando' | |
}; | |
function changeObject(developer) { | |
developer.name = 'Don ' + developer.name; | |
return developer; | |
} | |
var newDeveloper = changeObject(developer); | |
console.log(newDeveloper); | |
console.log( | |
'same object?', | |
developer === newDeveloper | |
); |
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
console.clear(); | |
var developer = { | |
name: 'Orlando' | |
}; | |
function changeObject(developer) { | |
var newDeveloper = {}; | |
for (var key in developer) { | |
newDeveloper[key] = 'Don ' + developer[key]; | |
} | |
return newDeveloper; | |
} | |
var newDeveloper = changeObject(developer); | |
console.log(newDeveloper) | |
console.log( | |
'same object?', | |
developer === newDeveloper | |
); |
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
console.clear() | |
let developer = { | |
name: 'Orlando' | |
} | |
const changeObject = (developer) => { | |
return Object.assign( | |
{}, | |
developer, | |
{name: 'Don ' + developer.name} | |
) | |
} | |
var newDeveloper = changeObject(developer) | |
console.log(newDeveloper) | |
console.log( | |
'same object?', | |
developer === newDeveloper | |
) |
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
console.clear() | |
let opcons = [1, 2, 3] | |
let addOpcon = (opcons) => { | |
return opcons.concat([4]) | |
} | |
var newOpcons = addOpcon(opcons) | |
console.log(newOpcons) | |
console.log( | |
'same array?', | |
opcons === newOpcons | |
) |
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
console.clear() | |
let array = [1, 2, 3] | |
console.log([0, ...array, 4]) | |
const numbers = (num1, num2, num3) => { | |
console.log(num1, num2, num3) | |
} | |
numbers(...array) |
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
console.clear() | |
let developer = { | |
name: 'Orlando', | |
surname: 'Bustos' | |
} | |
let developerWithKingOf = {kingOf: 'Sabre', ...developer} | |
console.log(developerWithKingOf) |
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
console.clear() | |
const variableParams = (name, ...developer) => { | |
console.log(name, developer) | |
} | |
variableParams('Orlando', 'Bustos', 'Don') |
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
console.clear() | |
let defaultValues = (opcon) => { | |
console.log(opcon) | |
} | |
defaultValues(4) | |
// Test without parameters and then create default parameter |
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
console.clear() | |
let developer = { | |
name: 'Bladimir', | |
surname: 'Yanez', | |
kingOf: 'Sabre' | |
} | |
let { surname } = developer | |
console.log(surname) | |
import { component } from 'React' | |
class vuelos extends component { | |
} | |
// Extract name too |
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
<script src="https://wzrd.in/standalone/expect@latest"></script> | |
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script> |
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
console.clear() | |
const toogleTodo = (todo) => { | |
//todo.completed = !todo.completed | |
return Object.assign( | |
{}, | |
todo, | |
{completed: !todo.completed} | |
) | |
return todo | |
} | |
const testToogleTodo = () => { | |
const todoBefore = { | |
id: 0, | |
text: 'Make a favor to Blad to join the mafia', | |
completed: false | |
} | |
const todoAfter = { | |
id: 0, | |
text: 'Make a favor to Blad to join the mafia', | |
completed: true | |
} | |
deepFreeze(todoBefore) | |
expect( | |
toogleTodo(todoBefore) | |
).toEqual(todoAfter) | |
} | |
testToogleTodo() | |
console.log('All tests clear') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment