Cracking the React.js Developer Assessment on Coderbyte 2024

YOGESH SINGH MALIK
10 min readSep 20, 2023

--

Lights, Camera, Code: React.js Developer Assessment: What to Expect on Coderbyte in 2023–24:

Are you gearing up for a React.js Developer assessment on Coderbyte? Congratulations on taking the first step toward a promising career in the world of web development. Assessments like these are not only a test of your technical skills but also a stepping stone to your dream job.

Table of Contents:

  1. Coding Questions
    1.1 Front-end Challenge
    1.2 Graph Challenge
    1.3 String Challenge
    1.4 Math Challenge
  2. Open Ended Questions
    2.1 Effective Teamwork Example
    2.2 Helping a Colleague Example
    2.3 Conflict Resolution Example
    2.4 Git Merge vs. Git Rebase
    2.5 Finding Files in a Commit
    2.6 Reverting a Public Commit
  3. Multiple Choice Questions
  4. Conclusion
  5. FAQs

1. Coding Questions

1.1 Front-end Challenge

Instructions:

We provided some simple React template code:

import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';

function Toggle() {

function handleClick() {
// todo
}

return (
<button>ON</button>
);
}

const container = document.getElementById('root');
const root = createRoot(container);
root.render(<Toggle />);

Your goal is to modify the component so that you can properly toggle the button to switch between an ON state and an OFF state. When the button is on and it is clicked, it turns off, and the text within it changes from ON to OFF and vice versa. Make use of component state for this challenge.

You are free to add classes and styles, but make sure you leave the element IDs as they are.

This is the solution I provided:

import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';

function Toggle() {
const [isOn, setIsOn] = useState(false);

function handleClick() {
setIsOn(!isOn);
}

const buttonStyle = {
backgroundColor: isOn ? 'green' : 'red',
color: 'white',
};

return (
<button onClick={handleClick} id="toggle" style={buttonStyle}>
{isOn ? 'ON' : 'OFF'}
</button>
);
}

const container = document.getElementById('root');
const root = createRoot(container);
root.render(<Toggle />);

1.2 Graph Challenge

Instructions:

Have the function GraphChallenge(strArr) take strArr, which will be an array of strings that models a non-looping Graph. The structure of the array will be as follows: The first element in the array will be the number of nodes N (points) in the array as a string. The next N elements will be the nodes which can be anything (A, B, C, ... Brick Street, Main Street, etc.). Then after the Nth element, the rest of the elements in the array will be the connections between all of the nodes. They will look like this: (A-B, B-C .. Brick Street-Main Street. . etc.). Although, there may exist no connections at all.

An example of strArr may be:
[“4", “A”, ”B”, “C”, “D”, “A-B”, “B-D”, ”B-C”, “C-D”]. Your program should return the shortest path from the first Node to the last Node in the array separated by dashes. So in the example above the output should be A-B-D. Here is another example with stArr being [“7”, “A”, “B”, ”C”, ”D”, ”E”, ”F”, ”G”, ”A-B”, “A-E”, “B-C”, “C-D”, ”D-F”, “E-D”, “F-G”]. The output for this array should be A-E-D-F-G. There will only ever be one shortest path for the array. If no path between the first and last node exists, return -1. The array will at minimum have two nodes. Also, the connection A-B for example, means that A can get to B and B can get to A.
Examples:
Input:

["5", "A", "B", "C", "D", "F", "A-B", "A-C", "B-C" , "C-D", "D-F"]

Output:

A-C-D-F

Input:

["4", "X", "Y", "Z", "W", "X-Y", "Y-Z", "X-W"]

Output:

X-W

The code I provided:

function GraphChallenge(strArr) {
const N = parseInt(strArr[0]);
const nodes = strArr.slice(1, N + 1);
const connections = strArr.slice(N + 1).join(' ').split(' '); // Split by spaces

const graph = new Map();

// Initialize nodes in the graph
for (const node of nodes) {
graph.set(node, new Set());
}

// Add connections
for (const connection of connections) {
const [nodeA, nodeB] = connection.split('-');
graph.get(nodeA).add(nodeB);
graph.get(nodeB).add(nodeA); // Since A can get to B and B can get to A
}

const startNode = nodes[0];
const endNode = nodes[N - 1];
const visited = new Set();
const queue = [[startNode, [startNode]]];

while (queue.length > 0) {
const [currentNode, path] = queue.shift();
if (currentNode === endNode) {
return path.join('-');
}
if (!visited.has(currentNode)) {
visited.add(currentNode);
for (const neighbor of graph.get(currentNode)) {
if (!visited.has(neighbor)) {
queue.push([neighbor, [...path, neighbor]]);
}
}
}
}

return -1; // No path found
}

// Example usage
console.log(GraphChallenge(["5", "A", "B", "C", "D", "F", "A-B", "A-C", "B-C", "C-D", "D-F"]));

1.3 String Challenge

Instructions:

Have the function StringChallenge(str1, str2) take both parameters being passed and return the string "true" if a portion of str1 characters can be rearranged to match str2, otherwise return the string "false." Punctuation and symbols will not be entered with the parameters.

function StringChallenge(str1, str2) {
// Function to sort strings alphabetically
function sortString(str) {
return str.split('').sort().join('');
}

// Sort both input strings alphabetically
const sortedStr1 = sortString(str1);
const sortedStr2 = sortString(str2);

// Compare the sorted strings
return sortedStr1 === sortedStr2 ? 'true' : 'false';
}

// Example usage
console.log(StringChallenge("cdore", "coder")); // Output: true
console.log(StringChallenge("h3llko", "hello")); // Output: false

1.4 Math Challenge

Instructions:

Have the function MathChallenge(num) take the num parameter being passed and return the string "true" if the parameter is a prime number, otherwise return the string "false." The range will be between 1 and 2^16.

function MathChallenge(num) {
if (num <= 1) {
return 'false';
}

if (num === 2) {
return 'true';
}

if (num % 2 === 0) {
return 'false';
}

for (let i = 3; i <= Math.sqrt(num); i += 2) {
if (num % i === 0) {
return 'false';
}
}

return 'true';
}

// Example usage
console.log(MathChallenge(19)); // Output: true
console.log(MathChallenge(110)); // Output: false

2. Open Ended Questions

2.1 Effective Teamwork Example

Question: Please share an example of effective teamwork that you have initiated?

Answer: Effective Teamwork Example:
In my previous role at {Company Name}, we had a critical project that required collaborative effort. To ensure effective teamwork, I initiated daily stand-up meetings where each team member discussed their progress, roadblocks, and goals for the day. This open communication helped us identify issues early, allocate resources efficiently, and meet our project deadlines successfully.

2.2 Helping a Colleague Example

Question: Please share an example of a time where you helped a colleague resolve an issue that was not your personal responsibility?

Answer: Helping a Colleague Example:
While working on the project, a colleague faced a challenge with data retrieval for a component. Although it wasn’t my primary responsibility, I offered assistance. We worked together to optimize the API call and implement caching, significantly improving data retrieval speed. This collaboration not only resolved the issue but also enhanced the overall performance of the component.

2.3 Conflict Resolution Example

Question: Please share an example of a time you resolved a conflict within your team?

Answer: Conflict Resolution Example:
During my time at {Company Name}, a conflict arose between two team members regarding the architecture of a new feature. To mediate, I organized a meeting where both parties expressed their concerns. I facilitated a compromise that incorporated elements from each person’s proposal, resulting in a more robust solution. This approach not only resolved the conflict but also fostered a better working relationship between the team members.

2.4 Git Merge vs. Git Rebase

Question: What is the difference between git merge and git rebase?

Answer: Git Merge vs. Git Rebase:
Git merge combines changes from one branch into another, creating a new merge commit. It’s suitable for preserving the commit history and maintaining a clear timeline. On the other hand, git rebase incorporates changes by moving or “replaying” commits from one branch onto another. This can result in a cleaner, linear commit history but may rewrite commit hashes, which can cause conflicts in a collaborative environment. Choose git merge for preserving history and git rebase for a cleaner, linear history.

2.5 Finding Files in a Commit

Question: How do you find a list of files that have been changed in a particular commit?

Answer: Finding Files in a Commit:
To find files changed in a particular commit, you can use the following Git command:

git diff --name-only <commit-SHA>^ <commit-SHA>

Replace <commit-SHA> with the actual SHA of the commit you want to inspect. This command lists the names of files that were modified in that commit.

2.6 Reverting a Public Commit

Question: What is the process to revert a commit that has already been pushed and made public?

Answer: Reverting a Public Commit:
To revert a commit that has already been pushed and made public, you can use the following Git workflow:

  1. First, ensure that your local branch is up-to-date with the remote branch:
git pull origin <branch-name>

Identify the commit you want to revert.

2. Create a new branch for the reversion:

git checkout -b revert-branch

3. Revert the commit with:

git revert <commit-SHA>

4. Push the revert branch to the remote repository:

git push origin revert-branch

5. Create a pull request for the revert branch and merge it into the main branch.

This process effectively undoes the changes introduced by the original commit while preserving the commit history and keeping everyone informed about the reversion.

3. Multiple Choice Questions (MCQs):

3.1 What is the correct syntax for an expression in JSX?

  • {{foo}}
  • :foo:
  • {foo}
  • //foo//

Answer: {foo}

3.2 What is needed for JSX to be correctly rendered in a browser?

  • reactJSXtoJS library
  • React convert extension
  • Transpiler (e.g., Babel)
  • A compiler class

Answer: Transpiler (e.g., Babel)

3.3 When rendering lists in React, what helps determine what needs to be re-rendered when a change occurs?

  • A unique id attribute via a class
  • A mapId property
  • A key attribute
  • A unique class on each element

Answer: A key attribute

3.4 What is the following a description of: A built-in React object that is used to contain data or information about the component?

  • propClass
  • state
  • component init() function
  • redux class

Answer: state

3.5 What function is required to properly update the state below?

handleClick() {
<FUNCTION> (prevState => ({
isToggleOn: !prevState.isToggleOn
}))
}
  • this.state.update
  • this.setState
  • this.updateState
  • this.updateState

Answer: this.setState

3.6 Which of the following is true about refs?

  • Updating refs causes the component and all child components to re-render.
  • Updating refs does not cause the component to re-render.
  • Updating refs causes any child component with a props argument to re-render.

Answer: Updating refs does not cause the component to re-render.

3.7 What optimization does useMemo help with?

  • It helps to cache data fetched from Redux stores.
  • It helps cache data that was retrieved from a call to useEffect.
  • It helps to avoid expensive calculations on every render.

Answer: It helps to avoid expensive calculations on every render.

3.8 If you want to combine componentDidMount and componentDidUpdate into a single hook, which one can you use?

  • useEffect
  • useState
  • useTransition
  • useCallback

Answer: useEffect

3.9 It is possible to render an element into any DOM element within a render function using which function?

  • Fragments
  • Portals
  • Profiler
  • Forwarding Refs

Answer: Portals

4. Conclusion

Preparing for the React.js Developer Assessment on Coderbyte can be a rewarding experience. By mastering React concepts and problem-solving skills, you’ll not only excel in this assessment but also set yourself up for success in your React.js developer career.

Good luck with your assessment, and remember to stay true to your skills and knowledge!

5. Frequently Asked Questions (FAQs):

Q1: How can I improve my problem-solving skills for coding challenges like these?

A: Improving problem-solving skills requires practice. Start with small coding challenges and gradually move to more complex ones. Also, study data structures and algorithms, as they are the building blocks of many coding problems.

Q2: Are there any recommended resources for learning React.js?

A: Yes, there are plenty of resources available. Some popular ones include the official React documentation, online courses on platforms like Udemy and Coursera, and React.js books. Also, check my other blog on FullStack Development.

Q3: What is the passing score for the Coderbyte React.js Developer Assessment?

A: The passing score may vary depending on the specific organization. It’s best to check with the organization conducting the assessment for their specific requirements.

Q4: Can I use external libraries or frameworks during the assessment?

A: The assessment instructions will typically specify whether you can use external libraries or frameworks. Make sure to read the instructions carefully.

Q5: How can I prepare for the open-ended questions?

A: Preparing for open-ended questions involves reflecting on your experiences and crafting concise and meaningful responses. Practice answering common behavioural and technical questions to be well-prepared.

This blog post is a comprehensive guide to help you excel in the React.js Developer Assessment on Coderbyte. We’ve covered coding questions, open-ended questions, and multiple-choice questions to prepare you for success. Best of luck with your assessment!

Note: The provided solutions in this blog post are for reference and learning purposes. Always strive to understand the concepts and solve problems independently.

Looking for juicy ballerbytes on the latest tech trends? Look no further! Follow me for weekly updates that will leave you buzzing with excitement.

Got development woes? Let me chop them away! As a Front-End/Full-Stack Development Freelancer on Upwork, I’ve got the skills to tackle even the thorniest of challenges.

Curious to see what I’m cooking up in my lab? Swing by my Personal Website and GitHub to get a taste of my latest projects.

Want to network with a digital nomad who’s always on the go? Let’s connect on LinkedIn! I’m always up for a chat about the latest industry trends and strategies.

Speaking of travel, follow me on Instagram to see what adventures I’m getting into as a tech-savvy globetrotter. From the beaches to mountains, I’m always on the move and ready for new challenges!

Check out this portfolio: https://yogeshmalikportfolio.netlify.app/

You can make your own custom Portfolio. Open the given portfolio link, fill the given form at the bottom and send me a mail or WhatsApp.

Your Support and feedback are greatly appreciated!

THANK YOU ALL

--

--

YOGESH SINGH MALIK

Technical writer, blogger and full-stack developer. When I'm not coding, you'll find me drinking tea or playing Basketball.