Code Monkey home page Code Monkey logo

react-grid-challenge's Introduction

React Interview Challenge

Objective

Develop a React application that dynamically generates an interactive grid of boxes based on user input, ensuring the grid is symmetric.

Instructions

  1. Provide a form with an input field and a "Create Grid" submit button. The user should input a single number to determine the dimensions of the grid (e.g., 3 for a 3x3 grid, i.e., n x n). Each box should display a number from 1 to n2, centered in the box. You should validate the user input and handle any invalid or empty inputs gracefully.
  2. When the user clicks on a box, the box should change its background color to blue, indicating that it is selected. If the user clicks on the same box again, the box should revert to its original background color, indicating that it is deselected.
  3. The user should be able to select multiple boxes at a time.
  4. There should be two buttons below the grid: “Reset” and “Shuffle”. The “Reset” button should clear all the selections and restore the original order of the numbers in the grid. The “Shuffle” button should randomly rearrange the numbers in the grid, using the Fisher-Yates shuffle algorithm. The “Reset” button should be disabled if there are no selections, and enabled otherwise.
  5. You can use the following TypeScript code to implement the Fisher-Yates shuffle algorithm. This function takes a 2-dimensional array of T as input and returns a shuffled copy of the array.
export function shuffle2dArray<T>(array: T[][]): T[][] {
  const result = array.map((row) => [...row]);
  for (let i = result.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [result[i], result[j]] = [result[j], result[i]];
  }
  for (let i = 0; i < result.length; i++) {
    for (let j = result[i].length - 1; j > 0; j--) {
      const k = Math.floor(Math.random() * (j + 1));
      [result[i][j], result[i][k]] = [result[i][k], result[i][j]];
    }
  }
  return result;
}

Evaluation Criteria:

Your solution will be evaluated based on the following criteria:

  • Accurate implementation of the specified features and validation.
  • Clean and maintainable code structure.
  • Adherence to React best practices.
  • Proper utilization of state, event handling, and input validation.
  • Efficient handling of dynamic grid generation based on user input.

react-grid-challenge's People

Contributors

nihar-hegde avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.