This file contains hidden or 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
| o_cache = {} | |
| def fibonacci(num): | |
| if num == 0: | |
| return num | |
| if num == 1: | |
| return num | |
| if num in o_cache: |
This file contains hidden or 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
| cache = [0, 1] | |
| def fibonacci(num): | |
| if num == 0: | |
| return num | |
| if num == 1: | |
| return num |
This file contains hidden or 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
| // We make use of ES6 imports | |
| import React, { Component, Fragment } from "react"; | |
| // we make use of ES6 classes and inheritance | |
| class TodoForm extends Component { | |
| // we make use of class variables to initialize state | |
| state = { | |
| todoName: "" | |
| }; |
This file contains hidden or 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
| import React, { Component, Fragment } from "react"; | |
| class TodoForm extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| todoName: "" | |
| }; | |
| this.handleInputChange = this.handleInputChange.bind(this); |
This file contains hidden or 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
| // assuming you are fetching data from a server returning a data structure shown below | |
| const todos = [ | |
| { | |
| id: 1, | |
| title: "Go Home", | |
| completed: false | |
| }, | |
| { | |
| id: 2, | |
| title: "Say Hi", |
This file contains hidden or 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
| // assuming you are fetching data from a server returning a data structure shown below | |
| const todos = [ | |
| { | |
| id: 1, | |
| title: "Go Home", | |
| completed: false | |
| }, | |
| { | |
| id: 2, | |
| title: "Say Hi", |
This file contains hidden or 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 Todo = ({ title, completed }) => ( | |
| <div> | |
| {title} | |
| {completed && <span> Well Done</span>} | |
| {/* We use short circuting to conditionally determine what to render*/} | |
| </div> | |
| ); |
This file contains hidden or 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
| import React from "react"; | |
| // We use ES6 classed and inheritence | |
| class Breweries extends React.Component { | |
| constructor() { | |
| // we use the constructor and call the constructor of the class we are in heriting from | |
| super(); | |
| // we initialize state in the constructor | |
| this.state = { | |
| breweries: [], |
This file contains hidden or 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
| componentDidMount() { | |
| fetch("https://api.openbrewerydb.org/breweries") | |
| .then(function(respose){return respose.json()}) | |
| .then(function(breweries){ | |
| this.setState({ breweries, loading: false }); | |
| }.bind(this)) | |
| .catch(function(error){ | |
| this.setState({ error, loading: false }); | |
| }.bind(this)); | |
| } |
This file contains hidden or 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
| componentDidMount() { | |
| // store the current value of this in a variable | |
| const $this = this; | |
| fetch("https://api.openbrewerydb.org/breweries") | |
| .then(function(respose){return respose.json()}) | |
| .then(function(breweries){ | |
| // use the variable to setState | |
| $this.setState({ breweries, loading: false }); | |
| }) | |
| .catch(function(error){ |
OlderNewer