---
title: "Discussion on \"Urgent 2k for JavaScript Developers\" | Hashnode"
description: "Discussion on \"Urgent 2k for JavaScript Developers\". Solve this challenge and win 2k"
url: "https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Urgent 2k for JavaScript Developers](https://unclebigbay.hashnode.dev/urgent-2k-for-javascript-developers?utm_source=hashnode&utm_medium=feed)

Solve this challenge and win 2k

Oct 14, 2021 · 2 min read · unclebigbay.hashnode.dev  
Updated Dec 5, 2021  
Read the article

-   [#explain-like-i-am-five](https://hashnode.com/tag/explain-like-i-am-five)
-   [#coding-challenge](https://hashnode.com/tag/coding-challenge)
-   [#challenge](https://hashnode.com/tag/challenge)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#problem-solving-skills](https://hashnode.com/tag/problem-solving-skills)

## Written by

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

@unclebigbay · Nigeria

  
[View profile](https://hashnode.com/@unclebigbay)

Software Engineer | Open-Source Contributor | Developer Educator

Software engineer and developer educator with over four years of experience building production-grade digital products for platforms serving millions of developers globally. Software engineer at Hashnode &amp; Bug0

## Responses 4

Markdown supported · ⌘↵ to post

[Victor Olorunfemi](https://hashnode.com/@Clefayomide)

[Oct 17, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/616bef4d7c361e513282269d)

### Summary

I enjoyed solving this problem. My process goes as follow:

1.  I created a function `` `getData() `` - function in javascript are code that performs a particular task when called.
2.  i declared a variable `didnt_submit` and assigned it to an empty array - variable in javascript are like a container that holds different type of information, while array in javascript are ordered list or collection of data
3.  The `getData()` function then fetches the data of all students and students who submitted from the google sheet which i have converted to `.txt` format
4.  The data gotten are now been stored in an array using the `split()` method - the `split()` method in javascript takes a string/strings and return a new array of that string/strings
5.  Now that we have converted our data - all\_students and student who submitted - into an array, lets fish out students who did not submit. i achieved this using the `forEach()` method in javascript - `forEach()` method loops through an array and executes a call back function once for each element in the array. Call back function are function that are passed into another function and are only executed after another function has finished executing. In this case, everytime the loop goes through the array of all the students, it checks if the email string returned from each loop is included in the array of students who submitted, if its not, it then pushes the string into the empty array `didnt_submit` that was declared earlier on

![Screenshot 2021-10-17 at 14-35-14 script js.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1634477792707/YqsU_9dk3.png)

[gist.github.com/clefayomide/d78c9c908a49baac31b8a…](https://gist.github.com/clefayomide/d78c9c908a49baac31b8a2756948232e)

[faruk suleiman](https://hashnode.com/@farukade)

[Oct 15, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168d72253401f641ba1767c)

![solution2.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1634260559165/mBQXu-GTl.jpeg)

This function picks an email from an array of students who submitted assignments and checks for a match in the array containing all students' emails while traversing. Once found, it deletes the email from the array (all students email array). At the end of the loop, the emails of students who did not submit will remain and the function returns an array containing their emails, the number of students who submitted, and the number of students who didn't. 😁😁😁 Not the best of solutions but it was fun giving it a try.

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Oct 15, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168d72253401f641ba1767c#reply-6169100418374f257327a033)

Well-done,

Please can you submit your code solution on GitHub gist, along with the file to test with?

Then share the URL here

[faruk suleiman](https://hashnode.com/@farukade)

[Oct 15, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168d72253401f641ba1767c#reply-6169502818374f257327a5c6)

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay) , Thank you, sir,

Here's the link below 👇👇. I saved the test emails in an array for easy access.

[gist.github.com/Omar-Faruk-tech/cbbdabe04947e4ce8…](https://gist.github.com/Omar-Faruk-tech/cbbdabe04947e4ce892af886b94e07b4)

[Favourite Jome](https://hashnode.com/@Favourite)

[Oct 14, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168b2ce53401f641ba1755f)

This is really an interesting challenge, it did take some thinking. so here's my answer.

```
const studentsData = async function () {
  const allStudent = await fetch("all-student.txt").then((res) => res.text());
  const studentsSubmitted = await fetch("students-submitted.txt").then((res) =>
    res.text()
  );

  const allStudentArr = allStudent.split("\n");
  const studentsSubmittedArr = studentsSubmitted.split("\n");

  const studentsNotSubmitted = allStudentArr.filter(
    (students) => !studentsSubmittedArr.includes(students)
  );

  console.log(allStudentArr, "all students");
  console.log(studentsSubmittedArr, "students that submitted");
  console.log(studentsNotSubmitted, "students who didn't submit");

  console.log(
    `Students who turned in there assignments are ${studentsSubmittedArr.length}, while ${studentsNotSubmitted.length} students didn't submit`
  );
  console.log(
    `Total number of students are ${
      studentsSubmittedArr.length + studentsNotSubmitted.length
    }`
  );
};

studentsData();
```

**Here's how I went about it**

First I converted the google sheet files to text (txt) files so that they can be readable in a JavaScript file.

Both file names are:

```
all-student.txt
students-submitted.txt
```

Then I declared an asynchronous function called `studentsData`, which is responsible for handling all data fetching and doing all calculations.

Since both, all students data and does students that submitted are given I used the snippets shown below to get the text files as strings into my script file.

```
  const allStudent = await fetch("all-student.txt").then((res) => res.text());
  const studentsSubmitted = await fetch("students-submitted.txt").then((res) =>
    res.text()
  );
```

> Note the use of `res.text()`, this is because it's a text file the script is reading.

If you should log `allStudent` and `studentsSubmitted` variables to the console, the data shown will be similar to the below picture:

![Screenshot from 2021-10-14 23-10-20.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1634249502924/T3nPMKgXL.png)

The above image is in a string type which isn't needed, so I converted it to an array for both `allStudent` and `studentsSubmitted` variables making use of the `split("\n")` method.

> "\\n" denotes **new line** also read about the split method [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)

```
 const allStudentArr = allStudent.split("\n");
 const studentsSubmittedArr = studentsSubmitted.split("\n");
```

Now for the final step, I filter through the array of `allStudentArr` (all students email) checking if students that submitted their assignment are in the all students array.

If the above statement is true, then return the remaining students for the all students array.

By doing this I got all the answers for the task.

```
const studentsNotSubmitted = allStudentArr.filter(
    (students) => !studentsSubmittedArr.includes(students)
  );
```

![Screenshot from 2021-10-14 23-34-50.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1634250954830/7VCunaqM9.png)

**Behind the scene** I did Google some things, like

-   making use of the split method _(I knew there was a way to convert strings to an array, but I couldn't remember)_
-   writing an async function that reads text files (initially I just used the fetch method separately which wouldn't have worked)

That's it, I enjoyed working on the challenge.

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Oct 15, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168b2ce53401f641ba1755f#reply-61690ff318374f257327a02e)

This looks nice 🙌,

Please can you submit your code solution on GitHub gist, along with the file to test with?

Then share the URL here.

Kudos for the well detailed guide

[Favourite Jome](https://hashnode.com/@Favourite)

[Oct 15, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168b2ce53401f641ba1755f#reply-61692a7c18374f257327a284)

Here's the gist file [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[gist.github.com/jomefavourite/bae4b45f7b4ae245382…](https://gist.github.com/jomefavourite/bae4b45f7b4ae245382c1a631ccb150e)

[Emmanuel Orji-Ihuoma](https://hashnode.com/@emmiiorji)

[Oct 14, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168884853401f641ba17323)

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1634240247443/0IbwWOJbq.png)

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1634241527301/cIGvv5twU.png)

The function receives both emails as string inputs. It checks emails in the general emails string that are not contained in the emails of those that submitted the assignment by utilizing the filter function. The emails are also converted to small letters in case there is a mix of cases.

It is expected that the file is downloaded in CSV (character-separated values) and the strings copied as inputs to the function.

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Oct 14, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168884853401f641ba17323#reply-6168afef53401f641ba17552)

can you create a Github gist and share the link?

[Emmanuel Orji-Ihuoma](https://hashnode.com/@emmiiorji)

[Oct 15, 2021](https://hashnode.com/posts/urgent-2k-for-javascript-developers/61685e0353401f641ba16faa/comment/6168884853401f641ba17323#reply-6169161453401f641ba179fa)

Here's the link to the Github gist.

File handling was not included for better clarity to a 5-year old.

[gist.github.com/emmiiorji/d6426bd2456f8d330cd481c…](https://gist.github.com/emmiiorji/d6426bd2456f8d330cd481ca83167a0f)
