• Oct 22, 2024 •C S
0 likes • 3 views
function removeElement(nums: number[], val: number): number { let zeroStartIndex = 0; for(let i = 0; i < nums.length; i++) { if(nums[i] !== val) { nums[zeroStartIndex] = nums[i]; zeroStartIndex++; } } return zeroStartIndex; };
• Nov 21, 2023 •AustinLeath
0 likes • 25 views
// Print Hello, World! console.log("Hello, World!");
• Oct 15, 2022 •CodeCatch
0 likes • 184 views
import { useState, useEffect, useRef } from "react"; // Usage function App() { // State value and setter for our example const [count, setCount] = useState(0); // Get the previous value (was passed into hook on last render) const prevCount = usePrevious(count); // Display both current and previous count value return ( <div> <h1> Now: {count}, before: {prevCount} </h1> <button onClick={() => setCount(count + 1)}>Increment</button> </div> ); } // Hook function usePrevious(value) { // The ref object is a generic container whose current property is mutable ... // ... and can hold any value, similar to an instance property on a class const ref = useRef(); // Store current value in ref useEffect(() => { ref.current = value; }, [value]); // Only re-run if value changes // Return previous value (happens before update in useEffect above) return ref.current; }
0 likes • 4 views
function removeDuplicates(nums: number[]): number { nums.splice(0, nums.length, ...Array.from(new Set(nums))); return nums.length; }; console.log(removeDuplicates([1, 2, 3, 4, 5, 6]))
• Oct 23, 2025 •opovolotskyi-7e4a
0 likes • 10 views
let state let prevValue function customState(initialValue){ if(state===undefined) { state=initialValue } function setState (newValue){ if(typeof newValue ==="function") { } state=newValue render() } return [state,setState] +(1) setState(2) setState((prev, next) => { return cancelIdleCallback() }) // state
• Mar 31, 2023 •Helper
0 likes • 6 views
const langToConfig = { 'javascript': { image: '', cmd: [''] }, 'php': { image: '', cmd: [''] }, }