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
let initialMemory = process.memoryUsage().heapUsed; | |
let word = process.argv[2]; | |
console.log(`Your word is ${word}`) | |
// Create a new array | |
let wordArray = []; | |
// Loop 1000 times, pushing into the array each time | |
for (let i = 0; i < 1000; i++){ |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>My Node Server</title> | |
</head> |
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 readline = require('readline'); | |
const fs = require('fs'); | |
// Create interface with a reading stream | |
const myInterface = readline.createInterface({ | |
input: fs.createReadStream('shoppingList.txt') | |
}); | |
// Create a write stream to custom file | |
const fileStream = fs.createWriteStream('shoppingResults.txt.'); |
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 readline = require('readline'); | |
const fs = require('fs'); | |
const myInterface = readline.createInterface({ | |
input: fs.createReadStream('shoppingList.txt') | |
}); | |
const printData = (data) => { | |
console.log(`Item: ${data}`); | |
} |
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
let {testNumber} = require('./game.js'); | |
process.stdout.write("I'm thinking of a number from 1 through 10. What do you think it is? \n(Write \"quit\" to give up.)\n\nIs the number ... "); | |
let playGame = (userInput) => { | |
let input = userInput.toString().trim(); | |
testNumber(input); | |
}; | |
process.stdin.on('data', playGame); |
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
module.exports = class Cat { | |
constructor(name, clawStrength) { | |
this.name = name; | |
this.clawStrength = clawStrength; | |
} | |
}; |
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'; | |
export class Example extends React.component { | |
componentDidUpdate(prevProps, prevState) { | |
alert('Component is done rendering!'); | |
} | |
render() { | |
return <h1>Hello world</h1>; | |
} |
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
/* Separating container components from presentational components is a popular React programming pattern. | |
Here’s the basic idea behind it: if a component has to have state, make calculations based on props, or manage any other complex logic, then that component shouldn’t also have to render HTML-like JSX. | |
Instead of rendering HTML-like JSX, the component should render another component. It should be that component’s job to render HTML-like JSX. | |
Following this pattern separates your business logic from your presentational logic. */ | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { GuineaPigs } from '../components/GuineaPigs'; | |
const GUINEAPATHS = [ |
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
// Normal way to display a prop: | |
export class MyComponentClass extends React.Component { | |
render() { | |
return <h1>{this.props.title}</h1>; | |
} | |
} | |
// Stateless functional component way to display a prop: | |
export const MyComponentClass = (props) => { | |
return <h1>{props.title}</h1>; |
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'; | |
export class BestSeller extends React.Component { | |
render() { | |
return ( | |
<li> | |
Title: <span> | |
{this.props.title} | |
</span><br /> | |