• 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)
• 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(); }} />
• Nov 18, 2022 •AustinLeath
0 likes • 0 views
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); } });
• Jan 17, 2021 •C S
const getSearchTerm = delimiter => { let searchTerm = ""; for (let i = 1; i < commands.length - 1; i++) searchTerm = searchTerm + commands[i] + delimiter; searchTerm += commands[commands.length - 1]; return searchTerm; };
• Nov 19, 2022 •CodeCatch
0 likes • 2 views
const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => r.concat(v))), [[]]); powerset([1, 2]); // [[], [1], [2], [1, 2]]
0 likes • 1 view
//JavaScript program to swap two variables //take input from the users let a = prompt('Enter the first variable: '); let b = prompt('Enter the second variable: '); // XOR operator a = a ^ b b = a ^ b a = a ^ b console.log(`The value of a after swapping: ${a}`); console.log(`The value of b after swapping: ${b}`);