Loading...
More JavaScript Posts
const linearSearch = (arr, item) => {for (const i in arr) {if (arr[i] === item) return +i;}return -1;};linearSearch([2, 9, 9], 9); // 1linearSearch([2, 9, 9], 7); // -1
const ResponsiveCardImg = styled(Card.Img)`// For screens wider than 768px@media(min-width: 768px) {// Your responsive styles here.}// For screens smaller than 768px@media(max-width: 768px) {// Your responsive styles here.}`export default function App() {return (<MainContainer><Container><Card text='white' bg='dark' style={styles.mainCard}><ResponsiveCardImgstyle={styles.cardImage}onClick={handleClick}src={apeImage}alt='Degenerate Ape Academy'/><Card.Body><Card.Title className='text-center' as='h2'>{apeId}</Card.Title></Card.Body></Card></Container></MainContainer>);}
class Graph {constructor(directed = true) {this.directed = directed;this.nodes = [];this.edges = new Map();}addNode(key, value = key) {this.nodes.push({ key, value });}addEdge(a, b, weight) {this.edges.set(JSON.stringify([a, b]), { a, b, weight });if (!this.directed)this.edges.set(JSON.stringify([b, a]), { a: b, b: a, weight });}removeNode(key) {this.nodes = this.nodes.filter(n => n.key !== key);[...this.edges.values()].forEach(({ a, b }) => {if (a === key || b === key) this.edges.delete(JSON.stringify([a, b]));});}removeEdge(a, b) {this.edges.delete(JSON.stringify([a, b]));if (!this.directed) this.edges.delete(JSON.stringify([b, a]));}findNode(key) {return this.nodes.find(x => x.key === key);}hasEdge(a, b) {return this.edges.has(JSON.stringify([a, b]));}setEdgeWeight(a, b, weight) {this.edges.set(JSON.stringify([a, b]), { a, b, weight });if (!this.directed)this.edges.set(JSON.stringify([b, a]), { a: b, b: a, weight });}getEdgeWeight(a, b) {return this.edges.get(JSON.stringify([a, b])).weight;}adjacent(key) {return [...this.edges.values()].reduce((acc, { a, b }) => {if (a === key) acc.push(b);return acc;}, []);}indegree(key) {return [...this.edges.values()].reduce((acc, { a, b }) => {if (b === key) acc++;return acc;}, 0);}outdegree(key) {return [...this.edges.values()].reduce((acc, { a, b }) => {if (a === key) acc++;return acc;}, 0);}}const g = new Graph();g.addNode('a');g.addNode('b');g.addNode('c');g.addNode('d');g.addEdge('a', 'c');g.addEdge('b', 'c');g.addEdge('c', 'b');g.addEdge('d', 'a');g.nodes.map(x => x.value); // ['a', 'b', 'c', 'd'][...g.edges.values()].map(({ a, b }) => `${a} => ${b}`);// ['a => c', 'b => c', 'c => b', 'd => a']g.adjacent('c'); // ['b']g.indegree('c'); // 2g.outdegree('c'); // 1g.hasEdge('d', 'a'); // trueg.hasEdge('a', 'd'); // falseg.removeEdge('c', 'b');[...g.edges.values()].map(({ a, b }) => `${a} => ${b}`);// ['a => c', 'b => c', 'd => a']g.removeNode('c');g.nodes.map(x => x.value); // ['a', 'b', 'd'][...g.edges.values()].map(({ a, b }) => `${a} => ${b}`);// ['d => a']g.setEdgeWeight('d', 'a', 5);g.getEdgeWeight('d', 'a'); // 5
function spam(times = 1,log = true){for(let i = 0; i < times; i++){$.get("backend-search.php", {term: (" "+Date.now())}).done(function(data){if(log) console.log(data);});}}spam(100000);
require("dotenv").config();const mongoose = require("mongoose");const db = process.env.MONGO_URI;const connectDB = async () => {try {await mongoose.connect(db, {useNewUrlParser: true,useUnifiedTopology: true,useFindAndModify: false,useCreateIndex: true});console.log("MongoDB Connected");} catch (err) {console.error(err.message);}};module.exports = connectDB;
function Welcome(props) {return <h1>Hello, {props.name}</h1>;}function App() {return (<div><Welcome name="Sara" /><Welcome name="Cahal" /><Welcome name="Edite" /></div>);}ReactDOM.render(<App />,document.getElementById('root'));