Skip to content

Instantly share code, notes, and snippets.

View isacjunior's full-sized avatar

Isac isacjunior

View GitHub Profile
const sumSales = (accumalator, element) => accumalator + element.sales
const totalSales = users.reduce(sumSales, 0)
console.log(totalSales) // 49991
function mapAge(array) {
const mapped = []
for (let i = 0; i < array.length; i++) {
mapped.push(array[i].age)
}
return mapped
}
const mappedAges = mapAge(users) // [26, 55, 29, 49, 19, 25, 26, 32]
const mapAges = users.map(element => element.age) // [26, 55, 29, 49, 19, 25, 26, 32]
const map = (array, transform) => {
mapped = []
for(let i = 0; i < array.length; i++)
mapped.push(transform(array[i]))
return mapped
}
const mapAges = map(users, element => element.age) // [26, 55, 29, 49, 19, 25, 26, 32]
const sales = [
{ name: 'João', amount: 11792.23, currency: 'BRL', country: 'Brazil', language: 'pt-BR' },
{ name: 'Manoel', amount: 3899.05, currency: 'EUR', country: 'Portugal', language: 'pt-PT' },
{ name: 'José', amount: 259, currency: "USD", country: 'United States', language: 'en-US' }
]
const formatCurrency = ({ amount, language, currency }) => {
return {
amountFormatted: amount.toLocaleString(language, { style: 'currency', currency: currency })
}
[
{ amountFormatted: "R$11.792,23" },
{ amountFormatted: "3 899,05 €" },
{ amountFormatted: "$259.00"}
]
render() {
return (
<>
<h1>Dipeex</h1>
<a href=”http://medium.com/dipeex">Medium</a>
</>
)
}
render() {
return [
<li key=”A”>First item</li>,
<li key=”B”>Second item</li>,
<li key=”C”>Third item</li>
]
}
// Criação do componente Wrapper
const Wrapper = ({ children }) => children
// utilizando o componente Wrapper
render() {
return (
<Wrapper>
<h1>Dipeex</h1>
<a href=”http://medium.com/dipeex">Medium</a>
<Wrapper/>
import { Fragment } from ‘react’
render() {
return (
<Fragment>
<div className=”title”>
<h1>Dipeex</h1>
<a href=”http://medium.com/dipeex">Medium</a>
</div>
<ChildA />