frontend-challenges
frontend-challenges copied to clipboard
FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
App.jsx ```jsx App.jsx import { useState, useRef, useEffect } from "react"; export default function App() { const [value, setValue] = useState(); const ref = useRef(() => { console.log("Submitted value:" +...
index.jsx ```jsx index.jsx import React, { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import "./styles.css"; import App from "./App"; const root = createRoot(document.getElementById("root")); root.render(); ``` TodoList.jsx ```jsx...
TodoList.jsx ```jsx TodoList.jsx import { useReducer } from "react"; const ADD_TODO = "ADD_TODO"; const TOGGLE_TODO = "TOGGLE_TODO"; const DELETE_TODO = "DELETE_TODO"; function todoReducer(state, action) { switch (action.type) { case ADD_TODO:...
TodoList.jsx ```jsx TodoList.jsx import { useState } from "react"; export function TodoList() { const [todos, setTodos] = useState([]); function onAddTodo(e) { e.preventDefault(); const formData = new FormData(e.currentTarget); const title =...
index.js ```js index.js export function promiseAny(promises) { const errors = []; return new Promise((resolve, reject) => { promises.forEach((promise) => { Promise.resolve(promise) .then(resolve) .catch((err) => { errors.push(err); if (errors.length === promises.length)...
index.js ```js index.js export function race(funcs) { return (callback) => { let done = false; if (funcs.length === 0) { callback(null, undefined); } funcs.forEach((fn) => { fn((err, data) => {...
index.js ```js index.js function promisify(func) { return new Promise((resolve, reject) => { func((err, data) => { if (err) { reject(err); } else { resolve(data); } }); }); } export function...
index.js ```js index.js export function reorderArray(items, newOrder) { for(let i = 0; i < newOrder.length; i++) { while(newOrder[i] !== i) { swap(items, i, newOrder[i]) swap(newOrder, i, newOrder[i]) } } }...
index.js ```js index.js /** * Creates a sum function with currying and chaining support. * @param {...number} args - Initial arguments * @returns {Function} Sum function that can be chained...
index.js ```js index.js /** * Custom implementation of JSON.stringify(). * @param {any} value - Value to stringify * @returns {string} JSON string representation */ function stringify(data) { if ([NaN, null,...