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
/* eslint-disable no-unused-expressions */ | |
const chai = require('chai'); | |
function documentoValido(ano) { | |
const hasNotArguments = !ano; | |
const isNotTypeNumber = typeof (ano) !== 'number'; | |
const currentYear = new Date().getFullYear(); | |
const isNotLessThanCurrentYear = ano < currentYear; |
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
// É possível atribuir um objeto a uma variável | |
let pessoa = {}; | |
// O imprimir, será impresso apenas um objeto | |
console.log(`Pessoa antes de atribuições: `); | |
console.log(pessoa); | |
// É possível realizar atribuições a esse objeto | |
pessoa.nome = 'Paulo'; | |
pessoa.sobrenome = 'Gesualdo'; |
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
// Considerando um array de números | |
const arrayNumeros = [1, 2, 3, 4, 5]; | |
console.log(arrayNumeros); | |
// É possível transformar um array em uma string, com os itens separados por vírgula | |
const stringNumeros = arrayNumeros.join(); | |
console.log(stringNumeros); | |
// É possível personalizar o caracter separador | |
const stringNumeros2 = arrayNumeros.join('.'); |
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
// Considerando dois arrays | |
const array1 = [1, 2]; | |
const array2 = [3, 4]; | |
// Uma das formas de combinar dois arrays é utilizando concat | |
const concat1 = array1.concat(array2); | |
console.log(concat1); | |
// É possível combiná-los utilizando também o operador spread (...) | |
const spread1 = [...array1, ...array2]; |
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
// É possível elaborar uma classe construtora | |
function Carro(marca, modelo) { | |
this.marca = marca, | |
this.modelo = modelo | |
}; | |
let argo = new Carro('Fiat', 'Argo'); | |
console.log(argo); |
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
// Considerando um array | |
const arrayCompleto = ['Primeiro','Segundo','Terceiro', 'Quarto']; | |
console.log(arrayCompleto) | |
// É possível cortar o primeiro item utilizando slice | |
const arrayCortado = arrayCompleto.slice(1); | |
console.log(arrayCortado); | |
// Isso não modifica o array completo, como pode-se ver abaixo: | |
console.log(arrayCompleto); |
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
// Considerando um array | |
const arrayNumeros = [1, 2, 3, 4] | |
// É possível encontrar elementos utilizando indexOf | |
// Ele retorna o índice onde está o elemento no vetor | |
// Caso o não tenha sido encontrado, ele retorna -1 | |
const elementoBuscado = 2; |
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
// Considerando um array de objetos (carros) | |
const carros = [ | |
{marca: 'Fiat', modelo: 'Argo'}, | |
{marca: 'Chevrolet', modelo: 'Onix'} | |
]; | |
console.log(carros); | |
// [ |
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
// Considerando um objeto celular | |
const celularSamsung = { | |
marca: 'Samsung', | |
tamanhoTela: { | |
vertical: 155, | |
horizontal: 75 | |
}, | |
bateria: 5000, | |
ligar: function(){ | |
console.log('Fazendo ligação de um Samsung...') |
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
// Considerando dois objetos criados a partir | |
// de uma função construtora | |
function criarCarro (marca, modelo) { | |
return { | |
marca, | |
modelo | |
}; | |
}; |
OlderNewer