• Jan 26, 2023 •AustinLeath
0 likes • 5 views
function printHeap(heap, index, level) { if (index >= heap.length) { return; } console.log(" ".repeat(level) + heap[index]); printHeap(heap, 2 * index + 1, level + 1); printHeap(heap, 2 * index + 2, level + 1); } //You can call this function by passing in the heap array and the index of the root node, which is typically 0, and level = 0. let heap = [3, 8, 7, 15, 17, 30, 35, 2, 4, 5, 9]; printHeap(heap,0,0)
• Feb 3, 2021 •C S
0 likes • 1 view
import React, { useState } from 'react' import Welcome from '../components/Welcome' function About() { const [showWelcome, setShowWelcome] = useState(false) return ( <div> {showWelcome ? <Welcome /> : null} </div> <div> {showWelcome && <Welcome /> } </div> ) } export default App
• Nov 19, 2022 •CodeCatch
0 likes • 0 views
const geometricProgression = (end, start = 1, step = 2) => Array.from({ length: Math.floor(Math.log(end / start) / Math.log(step)) + 1, }).map((_, i) => start * step ** i); geometricProgression(256); // [1, 2, 4, 8, 16, 32, 64, 128, 256] geometricProgression(256, 3); // [3, 6, 12, 24, 48, 96, 192] geometricProgression(256, 1, 4); // [1, 4, 16, 64, 256]
• Nov 18, 2022 •AustinLeath
const dragAndDropDiv = editor.container; dragAndDropDiv.addEventListener('dragover', function(e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; }); dragAndDropDiv.addEventListener("drop",function(e){ // Prevent default behavior (Prevent file from being opened) e.stopPropagation(); e.preventDefault(); const files = e.dataTransfer.items; // Array of all files console.assert(files.length >= 1); if (files[0].kind === 'file') { var file = e.dataTransfer.items[0].getAsFile(); const fileSize = file.size; const fileName = file.name; const fileMimeType = file.type; reader = new FileReader(); reader.onloadend = function(){ editor.setValue(reader.result); } reader.readAsText(file); }else{ //Maybe handle if text is dropped console.log(files[0].kind); } });
// Get the text that the user has selected const getSelectedText = () => window.getSelection().toString(); getSelectedText();
• Jan 25, 2023 •C S
0 likes • 8 views
// Vanilla JS Solution: var app = document.getElementById('app'); var typewriter = new Typewriter(app, { loop: true }); typewriter .typeString("I'm John and I'm a super cool web developer") .pauseFor(3000) .deleteChars(13) // "web developer" = 13 characters .typeString("person to talk with!") // Will display "I'm John and I'm a super cool person to talk with!" .start(); // React Solution: import Typewriter from 'typewriter-effect'; <Typewriter options={{ loop: true }} onInit={typewriter => { typewriter .typeString("I'm John and I'm a super cool web developer") .pauseFor(3000) .deleteChars(13) // "web developer" = 13 characters .typeString("person to talk with!") // Will display "I'm John and I'm a super cool person to talk with!" .start(); }} />