SHARE
TWEET

Untitled

a guest Mar 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2.  
  3. // Example code to reproduce the fibonnacci sequence
  4. // By: Shamaru Primera <shamaru001@gmail.com>
  5.  
  6. class App extends Component {
  7.   constructor(props){
  8.     super(props)
  9.     this.state = {
  10.       natural: []
  11.     }
  12.   }
  13.  
  14.   fibo(){
  15.     let natural = this.state.natural;
  16.  
  17.     if (natural.length == 0){
  18.       natural = [1]
  19.       this.setState({
  20.         natural
  21.       });
  22.     }
  23.     else{
  24.       let first  = natural[natural.length +(-1)];
  25.       let second = natural[natural.length +(-2)] || 0;
  26.       let plus = first + second;
  27.       natural.push(plus)
  28.       this.setState({
  29.         natural
  30.       })
  31.     }
  32.   }
  33.  
  34.   render(){
  35.     return (
  36.       <div>
  37.         <ul>{this.state.natural.map( (n) => <li>{n}</li>)}</ul>
  38.         <h3 onClick={this.fibo.bind(this)}>CLICK ME</h3>
  39.       </div>
  40.     )
  41.   }  
  42. }
  43.  
  44. export default App;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top