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 matriz = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]; | |
const valorInicial = []; | |
const vetor = matriz.reduce(function achatar(resultadoAnterior, lista) { | |
return [ ...resultadoAnterior, ...lista ]; | |
}, valorInicial); | |
console.log(vetor); | |
// [1, 2, 3, 4, 5, 6, 7, 8, 9] |
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 ingredientes = [ 'pao', 'tomate', 'queijo', 'ovo frito', 'ketchup', 'mostarda', 'pao' ]; | |
const lanche = ingredientes.reduce(function juntarComPao(resultadoAnterior, ingrediente) { | |
return `${resultadoAnterior}, ${ingrediente}`; | |
}, 'prato'); | |
console.log(`Aqui está o seu lanche: ${lanche}`); | |
// Aqui está o seu lanche: prato, pao, tomate, queijo, ovo frito, ketchup, mostarda, pao |
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 ingredientes = [ 'pao', 'tomate', 'queijo', 'ovo frito', 'ketchup', 'mostarda', 'pao' ]; | |
const lanche = ingredientes.reduce(function juntarComPao(resultadoAnterior, ingrediente) { | |
return `${resultadoAnterior}, ${ingrediente}`; | |
}); | |
console.log(`Aqui está o seu lanche: ${lanche}`); | |
// Aqui está o seu lanche: , pao, tomate, queijo, ovo frito, ketchup, mostarda, pao |
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
// __tests__/accordion.rtl.js | |
import '@testing-library/jest-dom/extend-expect' | |
import React from 'react' | |
import {render, screen} from '@testing-library/react' | |
import userEvent from '@testing-library/user-event' | |
import Accordion from '../accordion' | |
test('can open accordion items to see the contents', () => { | |
const hats = {title: 'Favorite Hats', contents: 'Fedoras are classy'} | |
const footware = { | |
title: 'Favorite Footware', |
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
test('setOpenIndex sets the open index state properly', () => { | |
const wrapper = mount(<Accordion items={[]} />) | |
- expect(wrapper.state('openIndex')).toEqual(0) | |
+ expect(wrapper.state('openIndexes')).toEqual([0]) | |
wrapper.instance().setOpenIndex(1) | |
- expect(wrapper.state('openIndex')).toEqual(1) | |
+ expect(wrapper.state('openIndexes')).toEqual([1]) | |
}) |
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
class Accordion extends React.Component { | |
- state = {openIndex: 0} | |
- setOpenIndex = openIndex => this.setState({openIndex}) | |
+ state = {openIndexes: [0]} | |
+ setOpenIndex = openIndex => this.setState({openIndexes: [openIndex]}) | |
render() { | |
- const {openIndex} = this.state | |
+ const {openIndexes} = this.state | |
return ( | |
<div> |
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
// __tests__/accordion.enzyme.js | |
import React from 'react' | |
// if you're wondering why not shallow, | |
// then please read <https://kcd.im/shallow> | |
import Enzyme, {mount} from 'enzyme' | |
import EnzymeAdapter from 'enzyme-adapter-react-16' | |
import Accordion from '../accordion' | |
// Setup enzyme's react adapter | |
Enzyme.configure({adapter: new EnzymeAdapter()}) | |
test('setOpenIndex sets the open index state properly', () => { |
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
// accordion.js | |
import React from 'react' | |
import AccordionContents from './accordion-contents' | |
class Accordion extends React.Component { | |
state = {openIndex: 0} | |
setOpenIndex = openIndex => this.setState({openIndex}) | |
render() { | |
const {openIndex} = this.state | |
return ( | |
<div> |
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
public class Observer<T> | |
{ | |
public Observer() { } | |
public Observer(T initValue) | |
{ | |
value = initValue; | |
} | |
private T value; |
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 Nightmare = require('nightmare') | |
const nightmare = Nightmare({ show: true }) | |
nightmare | |
.goto('http://blablablablabla/logon/logon.asp') | |
.wait(() => { | |
return document.querySelector('[name=username]') !== null; | |
}) | |
.evaluate(() => { | |
document.querySelector('[name=username]').value = "visitante"; |
NewerOlder