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
// Create a function that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers. | |
// 1. via "if else" statements | |
func evenOrOdd(_ number: Int) -> String { | |
if number % 2 == 0 { | |
return "Even" | |
} else { | |
return "Odd" | |
} |
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
console.log(process.argv); | |
function fibonacci(n, cache) { | |
cache = cache || {}; | |
if (cache[n]) { return cache[n] }; | |
if (n <= 2) { return 1 }; | |
return cache[n] = fibonacci(n - 1, cache) + fibonacci(n - 2, cache); | |
} |
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
// Source: Dan Abramov | |
// https://codepen.io/gaearon/pen/gWWZgR?editors=0010 | |
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import "./index.css"; | |
function Square(props) { | |
return ( | |
<button className="square" onClick={props.onClick}> |
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
// Game component: | |
handleClick(i) { | |
const locations = [ | |
[1, 1], | |
[2, 1], | |
[3, 1], | |
[1, 2], | |
[2, 2], | |
[3, 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
// Inside Game's render method | |
const moves = history.map((step, move) => { | |
const desc = move | |
? "Go to move #" + move + " @ " + history[move].location | |
: 'Go to game start'; | |
return ( | |
<li key={move}> | |
<button onClick={() => this.jumpTo(move)}>{desc}</button> | |
</li> |
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
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import "./index.css"; | |
function Square(props) { | |
return ( | |
<button className="square" onClick={props.onClick}> | |
{props.value} | |
</button> | |
); |
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
// Inside Game's render method | |
// Note <button>'s child | |
const moves = history.map((step, move) => { | |
const desc = move | |
? "Go to move #" + move + " @ " + history[move].location | |
: "Go to game start"; | |
return ( | |
<li key={move}> | |
<button onClick={() => this.jumpTo(move)}> |
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
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import "./index.css"; | |
function Square(props) { | |
return ( | |
<button className="square" onClick={props.onClick}> | |
{props.value} | |
</button> | |
); |
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
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import "./index.css"; | |
function Square(props) { | |
return ( | |
<button className="square" onClick={props.onClick}> | |
{props.value} | |
</button> | |
); |
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 Board extends React.Component { | |
renderSquare(i) { | |
return ( | |
<Square | |
key={"square " + i} | |
value={this.props.squares[i]} | |
onClick={() => this.props.onClick(i)} | |
/> | |
); | |
} |
OlderNewer