0% found this document useful (0 votes)
26 views

Report Node JS Developer Backend Jluissucuc

Uploaded by

sdeoro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Report Node JS Developer Backend Jluissucuc

Uploaded by

sdeoro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Luis Sucuc

87 Luis Sucuc PDF generated at: 6 Jun 2024 23:13:02 UTC

Back-End Developer (Node) View this report on HackerRank

Score
87% • 143 / 165
scored in Node JS Developer (Backend) in 119 min 26 sec on 6 Jun 2024 16:10:58 -05

Candidate Information
Email [email protected]

Test Node JS Developer (Backend)

Candidate Packet View

Taken on 6 Jun 2024 16:10:58 -05

Time taken 119 min 26 sec/ 120 min

Work Experience > 5 years

Invited by Sandra

Invited on 5 Jun 2024 10:36:04 -05

Skill Distribution

No. Skill Score

Node.js
1 0%
Basic

Candidate Report Page 1 of 21


Luis Sucuc

JavaScript
2 50%
Basic

JavaScript
3 50%
Advanced

Problem Solving
4 94%
Basic

Tags Distribution
Medium 90% Javascript 0%

Node.js 0% Hard 25%

JavaScript 50% Closure 50%

Variable Scopes 50% Strings 100%

Implementation 100% Problem Solving 94%

File Manipulation 88% Scripting 88%

Regex 88% Back-End Development 88%

Questions

Time
Status No. Question Skill Score
Taken

Express JS 2 min
1 Node.js (Basic) 0/5
Multiple Choice 9 sec

Candidate Report Page 2 of 21


Luis Sucuc

2 min
APIs in Express JS 2
2 20 Node.js (Basic) 0/5
Multiple Choice
sec

5 min
JavaScript Function JavaScript +1
3 11 2.5/5
Multiple Choice (Basic)
sec

34
Ancestral Names min Problem
4 75/75
Coding 15 Solving (Basic)
sec

1
hour
GET Requests for GIF Images 14 Problem
5 66/75
Approximate Solution min Solving (Basic)
18
sec

1. Express JS Incorrect

Multiple Choice Medium Javascript Node.js

Question description

What happens when a client sends a GET request to http://localhost:3000/users?

const http = require("http");

http.createServer((request, response) => {


if (request.method === "GET" && request.url === "/users") {
response.writeHead(200, { "Content-Type": "application/json" });
response.end([
{ name: "Alice", age: 25 },
{ name: "Bob", age: 30 },
]);

Candidate Report Page 3 of 21


Luis Sucuc

} else {
response.writeHead(404, { "Content-Type": "text/plain" });
response.end("Not found");
}
})
.listen(3000);

console.log("Server is running on port 3000");

Interviewer guidelines
The code has a syntax error. The response.end method is called with an array as its argument, which will
cause a TypeError to be thrown because response.end expects a string or a buffer. To fix this error, the
array should be converted to a JSON string using JSON.stringify.

Candidate's Solution

Options: (Expected answer indicated with a tick)

The server responds with a JSON array that contains user data.

The server responds with a plain text message that contains the request data.

The server responds with an error.

The server sends an empty response.

No comments.

Candidate Report Page 4 of 21


Luis Sucuc

2. APIs in Express JS 2 Incorrect

Multiple Choice Javascript Node.js Hard

Question description

What is the output of the following code?

const http = require("http");


var a = 8;
var y = 2;
const server = http.createServer((req, res) => {
a *= y;

setImmediate(() => {
a /= 2;
});

process.nextTick(() => {
a += 2;
});
console.log(a);

res.end("End");
});

server.listen(3000, () => {});

Interviewer guidelines
The exact order in which these operations are executed is not guaranteed, and can change based on
various factors such as the state of the system, the availability of resources, and the behavior of the event
loop.
So, while the output of the code will always be a specific value, that value may not be the same each time
the code is executed, as it can be influenced by the conditions of the system at runtime.

Candidate's Solution

Options: (Expected answer indicated with a tick)

Candidate Report Page 5 of 21


Luis Sucuc

10

The output is not guaranteed to be a specific value as the execution order may vary.

The output throws an error because the execution order is not guaranteed.

No comments.

3. JavaScript Function Partially correct

Multiple Choice JavaScript Hard Closure Variable Scopes

Question description

Have a look at the following code snippet and select the appropriate statement(s):

function Candidate(name, age, stream, grad, school) {


this.name = name;
this.age = age;
this.stream = stream;
this.grad = grad;
this.display = function(p) {
console.log("First Name: " + p.name.firstName);
console.log("Age: " + p.age);
console.log("Stream: " + p.stream);
console.log("School: " + p.school.name);
console.log("Grad: " + p.grad);

Candidate Report Page 6 of 21


Luis Sucuc

}
}

The below call is made:

const ob = new Candidate("Ashley", 21, "Science", "B.Tech", "St.Jones");


ob.display(ob);

Candidate's Solution

Options: (Expected answer indicated with a tick)

<p>The output generated is:</p> <p>First Name: undefined</p> <p>Age: 21</p>


<p>Stream: Science</p> <p>School: undefined</p> <p>Grad: B.Tech</p> <p>&nbsp;</p>

<p>&nbsp;</p> <p>&nbsp;</p>

<p>It will result in a type&nbsp;error due to line 8.</p>

<p>It will result in a type&nbsp;error due to line 10.</p>

<p>console.log(ob.name.lastName) will give a type error.</p>

<p>console.log(ob.name.lastName) will output undefined.</p>

Candidate Report Page 7 of 21


Luis Sucuc

No comments.

4. Ancestral Names Correct

Coding Medium Strings Implementation Problem Solving

Question description

Given a list of strings comprised of a name and a Roman numeral, sort the list first by name, then by the
decimal value of the Roman numeral.
In Roman numerals, a value is not repeated more than three times. At that point, a smaller value
precedes a larger value to indicate subtraction. For example, the letter I represents the number 1, and
V represents 5. Reason through the formation of 1 to 10 below, and see how it is applied in the following
lines.

I, II, III, IV, V, VI, VII, VIII, IX, and X represent 1 through 10.
XX, XXX, XL, and L are 20, 30, 40, and 50.
For any other two-digit number < 50, concatenate the Roman numeral(s) that represent its multiples
of ten with the Roman numeral(s) for its values < 10. For example, 43 is 40 + 3 = 'XL' + 'III' = 'XLIII'

Example
names = ['Steven XL', 'Steven XVI', 'David IX', 'Mary XV', 'Mary XIII', 'Mary XX']

The result with Roman numerals is the expected return value. Written in decimal and sorted, they are
['David 9', 'Mary 13', 'Mary 15', 'Mary 20', 'Steven 16', 'Steven 40']. The return array is ['David IX', 'Mary
XIII', 'Mary XV', 'Mary XX', 'Steven XVI', 'Steven XL'].

Function Description
Complete the function sortRoman in the editor below.

sortRoman has the following parameters:


names[n]: an array of strings comprised of names and roman numerals

Candidate Report Page 8 of 21


Luis Sucuc

Returns
string[n]: an array of strings sorted first by given name, then by ordinal

Constraints
1 ≤ n ≤ 50
Each names[i] is a single string composed of 2 space-separated values: givenName and
romanNumeral.
romanNumeral represents a number between 1 and 50, inclusive.
1 ≤ |givenName| ≤ 20
Each givenName starts with an uppercase letter ascii[A-Z] which is followed by lowercase letters
ascii[a-z].
There is a space between givenName and romanNumeral
Each names[i] is distinct.

INPUT FORMAT FOR CUSTOM TESTING

Input from stdin will be processed as follows and passed to the function.

The first line contains an integer n, the size of the array names.
Each of the next n lines contains an element names[i].

SAMPLE CASE 0

Sample Input

STDIN Function
----- -----
2 → names[] size n = 2
Louis IX → names = ['Louis IX', 'Louis VIII']
Louis VIII

Sample Output

Louis VIII
Louis IX

Explanation

Candidate Report Page 9 of 21


Luis Sucuc

Sort first by givenName and then, if givenName is not unique, by the value of the Roman numeral. In
decimal, the list is sorted ['Louis 8', 'Louis 9'].

SAMPLE CASE 1

Sample Input

STDIN Function
----- -----
2 → names[] size n = 2
Philippe I → names = ['Philippe I', 'Philip II']
Philip II

Sample Output

Philip II
Philippe I

Interviewer guidelines
Python 3 Solution

def roman_to_int(roman):
roman_values = {'I':1,'V':5,'X':10,'L':50}
result = 0
prev_value = 0
for char in reversed(roman):
value = roman_values[char]
if value >= prev_value:
result += value
else:
result -=value
prev_value = value
return result

def sortRoman(names):
sorted_names = sorted(names,key=lambda x:(x.split()[0],roman_to_int(x.split()[1])))
return sorted_names

Candidate's Solution Language used: JavaScript (Node.js)

Candidate Report Page 10 of 21


Luis Sucuc

1 'use strict';
2
3 const fs = require('fs');
4
5 process.stdin.resume();
6 process.stdin.setEncoding('utf-8');
7
8 let inputString = '';
9 let currentLine = 0;
10
11 process.stdin.on('data', function(inputStdin) {
12 inputString += inputStdin;
13 });
14
15 process.stdin.on('end', function() {
16 inputString = inputString.split('\n');
17
18 main();
19 });
20
21 function readLine() {
22 return inputString[currentLine++];
23 }
24
25
26 /*
27 * Complete the 'sortRoman' function below.
28 *
29 * The function is expected to return a STRING_ARRAY.
30 * The function accepts STRING_ARRAY names as parameter.
31 */
32
33 // Fixed values for roman numbers
34 const romanValues = {
35 I : 1,
36 V : 5,
37 X : 10,
38 L : 50
39 }
40
41 function romanToArabic(roman) {
42 let arabicValue = 0
43 let prevValue = 0
44
45 for (let n = roman.length -1 ; n >= 0 ; n-- ) {
46 const currentNum = romanValues[roman[n]]

Candidate Report Page 11 of 21


Luis Sucuc

47 // When the current number is greater than prevValue then it


subtracts to the total number
48 if (currentNum < prevValue) {
49 arabicValue -= currentNum
50 }
51 else {
52 arabicValue += currentNum
53 }
54
55 prevValue = currentNum
56 }
57
58 return arabicValue
59 }
60
61
62 function shortNames(a, b) {
63 // Separe name an number form string
64 const [nameA, numberA] = a.split(" ")
65 const [nameB, numberB] = b.split(" ")
66
67 if(nameA === nameB) {
68 return romanToArabic(numberA) - romanToArabic(numberB)
69 }
70 // When are differentes, whe use the names for compare
71 return nameA.localeCompare(nameB)
72 }
73
74 function sortRoman(names) {
75 return names.sort(shortNames)
76 }
77 function main() {
78 const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
79
80 const namesCount = parseInt(readLine().trim(), 10);
81
82 let names = [];
83
84 for (let i = 0; i < namesCount; i++) {
85 const namesItem = readLine();
86 names.push(namesItem);
87 }
88
89 const result = sortRoman(names);
90
91 ws.write(result.join('\n') + '\n');

Candidate Report Page 12 of 21


Luis Sucuc

92
93 ws.end();
94 }
95

TIME MEMORY
TESTCASE DIFFICULTY TYPE STATUS SCORE
TAKEN USED

Testcase
Easy Sample Success 1 0.0428 sec 42 KB
0

Testcase
Easy Sample Success 1 0.047 sec 44.7 KB
1

Testcase
Easy Sample Success 1 0.0466 sec 44.7 KB
2

Testcase
Easy Sample Success 6 0.0832 sec 44.6 KB
3

Testcase
Easy Sample Success 11 0.0489 sec 44.6 KB
4

Testcase
Easy Hidden Success 11 0.0708 sec 44.7 KB
5

Testcase
Easy Hidden Success 11 0.0503 sec 44.6 KB
6

Testcase
Easy Hidden Success 11 0.0461 sec 44.7 KB
7

Testcase
Easy Hidden Success 11 0.058 sec 44.6 KB
8

Candidate Report Page 13 of 21


Luis Sucuc

Testcase
Easy Hidden Success 11 0.0575 sec 44.7 KB
9

No comments.

5. GET Requests for GIF Images Partially correct

Approximate Solution File Manipulation Scripting Regex Medium Problem Solving

Back-End Development

Question description

You are given a log file with a list of responses, some of the records in the log file may contain filenames.
Generate a new file containing the unique names of all gif files that were requested via GET and that had
a response code of 200.
A sample and the structure of the text file containing the responses are given below.

Sample log record:

burger.letters.com - - [01/Jul/1995:00:00:12 -0400] "GET /shuttle/countdown/video/livevideo.GIF HTT


P/1.0" 200 0
burger.letters.com - - [01/Jul/1995:00:00:12 -0400] "GET /images/NASA-logosmall.gif HTTP/1.0" 304 0

Log File Structure:

Hostname - - Timestamp Request HTTP Response


Bytes
Code

"GET
[01/Jul/1995:00:00:12
burger.letters.com
- - /shuttle/countdown/video/livevideo.GIF 200 0
-0400]
HTTP/1.0"

Hostname of - - Timestamp Format The request is enclosed in quotes The HTTP


the host that response
code.

Candidate Report Page 14 of 21


Luis Sucuc

made the
request

Missing column values are denoted by a hyphen (i.e. -).


Timestamp Format: DD: day of the month, mmm: name of the month, YYYY: year, HH:MM:SS - 24-hour
time format, -0400 is the time zone

Given a filename that denotes a text file in the current working directory. Create an output file with the
name "gifs_" prefixed to the filename (gifs_filename) which stores the unique gif filenames that match
the requirements.

Example: filename = "hosts_access_log_00.txt", process the records in hosts_access_log_00.txt and create


an output file named gifs_hosts_access_log_00.txt.

Write the name of a GIF file (without its path) to the output file, for each of the records in the input file
which satisfy the below:
The GIF file was requested by a GET request.
The record has an HTTP response code of 200.

Note:
The output file has to be written to the current directory.
The line order in the output file does not matter.
There must not be any duplicates (if duplicates exist, you will receive only 70% of the score).

Constraints
The log file contains no more than 2 × 105 records.

INPUT FORMAT FOR CUSTOM TESTING

Input from stdin will be processed as follows and passed to the function.

The only line contains a string filename, the name of the log file.

SAMPLE CASE 0

Sample Input 0

hosts_access_log_00.txt

Candidate Report Page 15 of 21


Luis Sucuc

Sample Output 0
Given filename = "hosts_access_log_00.txt", process the records in hosts_access_log_00.txt and create
an output file named gifs_hosts_access_log_00.txt that contains the following rows:

livevideo.GIF
count.gif
NASA-logosmall.gif
KSC-logosmall.gif

Explanation 0
The log file hosts_access_log_00.txt contains the following log records:

unicomp6.unicomp.net - - [01/Jul/1995:00:00:06 -0400] "GET /shuttle/countdown/ HTTP/1.0" 200 39


85
burger.letters.com - - [01/Jul/1995:00:00:11 -0400] "GET /shuttle/countdown/liftoff.html HTTP/1.0" 3
04 0
burger.letters.com - - [01/Jul/1995:00:00:12 -0400] "GET /images/NASA-logosmall.gif HTTP/1.0" 304
0
burger.letters.com - - [01/Jul/1995:00:00:12 -0400] "GET /shuttle/countdown/video/livevideo.GIF HT
TP/1.0" 200 0
d104.aa.net - - [01/Jul/1995:00:00:13 -0400] "GET /shuttle/countdown/ HTTP/1.0" 200 3985
unicomp6.unicomp.net - - [01/Jul/1995:00:00:14 -0400] "GET /shuttle/countdown/count.gif HTTP/1.
0" 200 40310
unicomp6.unicomp.net - - [01/Jul/1995:00:00:14 -0400] "GET /images/NASA-logosmall.gif HTTP/1.0"
200 786
unicomp6.unicomp.net - - [01/Jul/1995:00:00:14 -0400] "GET /images/KSC-logosmall.gif HTTP/1.0" 2
00 1204
d104.aa.net - - [01/Jul/1995:00:00:15 -0400] "GET /shuttle/countdown/count.gif HTTP/1.0" 200 4031
0
d104.aa.net - - [01/Jul/1995:00:00:15 -0400] "GET /images/NASA-logosmall.gif HTTP/1.0" 200 786

A review of the data above:


1. The fourth log record:

burger.letters.com - - [01/Jul/1995:00:00:12 -0400] "GET /shuttle/countdown/video/livevideo.GI


F HTTP/1.0" 200 0

A GET request requested a file named livevide.GIF and the HTTP response code was 200.
2. The sixth log record:

unicomp6.unicomp.net - - [01/Jul/1995:00:00:14 -0400] "GET /shuttle/countdown/count.gif HTT


P/1.0" 200 40310

And the ninth log record:

Candidate Report Page 16 of 21


Luis Sucuc

d104.aa.net - - [01/Jul/1995:00:00:15 -0400] "GET /shuttle/countdown/count.gif HTTP/1.0" 200


40310

In both records, a GET request requested a file named count.gif and the HTTP response code was
200.
3. The seventh log record:

unicomp6.unicomp.net - - [01/Jul/1995:00:00:14 -0400] "GET /images/NASA-logosmall.gif HTTP/


1.0" 200 786

A GET request requested a file named NASA-logosmall.gif and the HTTP response code was 200.
4. The eighth log record:

unicomp6.unicomp.net - - [01/Jul/1995:00:00:14 -0400] "GET /images/KSC-logosmall.gif HTTP/


1.0" 200 1204

A GET request requested a file named KSC-logosmall.gif and the HTTP response code was 200.
Append the four distinct GIF file names satisfying our conditions to the output file.

Candidate's Solution Language used: JavaScript (Node.js)

1 process.stdin.resume();
2 process.stdin.setEncoding('ascii');
3
4 let consoleInput = '';
5 process.stdin.on('data', (data) => {
6 consoleInput += data;
7 });
8
9 process.stdin.on('end', () => {
10 consoleInput = consoleInput.split('\n');
11 main();
12 });
13
14 let currentLine = 0;
15 function readLine() {
16 if (currentLine >= consoleInput.length) {
17 return null;
18 }
19
20 return consoleInput[currentLine++];
21 }
22
23 process.stdin.resume();

Candidate Report Page 17 of 21


Luis Sucuc

24 process.stdin.setEncoding('ascii');
25
26 let consoleInput = '';
27 process.stdin.on('data', (data) => {
28 consoleInput += data;
29 });
30
31 process.stdin.on('end', () => {
32 consoleInput = consoleInput.split('\n');
33 main();
34 });
35
36 let currentLine = 0;
37 function readLine() {
38 if (currentLine >= consoleInput.length) {
39 return null;
40 }
41
42 return consoleInput[currentLine++];
43 }
44
45
46 const fs = require('fs')
47 const readline = require('readline')
48
49 function main() {
50 // read the string filename
51 const filename = readLine();
52
53 // Read each line of the file
54 const fileStream = fs.createReadStream(filename)
55
56 // Create interface to readLines
57 const rl = readline.createInterface({
58 input: fileStream
59 })
60
61 // Contains all names files
62 let finalFileNames = new Set()
63
64 rl.on('line', (line) => {
65
66 // Regular Expresion
67 const regex = /"GET\s(\/[^"]*)\sHTTP\/[^"]*"\s(\d{3})/
68
69 const match = line.match(regex)

Candidate Report Page 18 of 21


Luis Sucuc

70
71 if (match) {
72 const path = match[1]
73 const lineFileName = path.split('/').pop() || null;
74 const statusCode = match[2]
75
76 if( lineFileName && lineFileName.toLowerCase().includes(".gif")
&&
77 statusCode === '200' ) {
78 finalFileNames.add(lineFileName)
79 }
80 }
81
82 // For testing purposes
83 else {
84 if (line.toLowerCase().includes(".gif") &&
line.toLowerCase().includes("get")) {
85 console.log(line)
86 }
87 }
88
89
90 })
91
92 rl.on('close', (line) => {
93 const pathFile = `gifs_${filename}`
94 const dataFile = Array.from(finalFileNames).join('\n')
95 fs.writeFile(
96 pathFile,
97 dataFile,
98 (error) => {
99 if (error) {
100 console.error(error);
101 }
102 else {
103 //console.log('File created successfully')
104 }
105 }
106
107 )
108 })
109
110 }
111
112

Candidate Report Page 19 of 21


Luis Sucuc

TIME MEMORY
TESTCASE DIFFICULTY TYPE STATUS SCORE
TAKEN USED

0.0425
TestCase 0 Easy Sample Success 1/1 42.3 KB
sec

0.0751
TestCase 1 Easy Sample Success 1/1 40.1 KB
sec

0.0448
TestCase 2 Easy Sample Success 1/1 43.6 KB
sec

0.0531
TestCase 3 Easy Hidden Success 9/9 44.3 KB
sec

0.0583
TestCase 4 Easy Hidden Success 9/9 49 KB
sec

0.0721
TestCase 5 Easy Hidden Success 9/9 50 KB
sec

0.0668
TestCase 6 Easy Hidden Success 9/9 51 KB
sec

0.1023
TestCase 7 Easy Hidden Success 8/8 55.8 KB
sec

0.1522
TestCase 8 Easy Hidden Success 8/8 58.9 KB
sec

0.1424
TestCase 9 Easy Hidden Success 8/8 67.4 KB
sec

Candidate Report Page 20 of 21


Luis Sucuc

TestCase Wrong 0.1718


Easy Hidden 0/3 65.9 KB
10 Answer sec

TestCase 0.3848
Easy Hidden Success 3/3 64.4 KB
11 sec

TestCase Wrong 0.5948


Easy Hidden 0/3 68.1 KB
12 Answer sec

TestCase Wrong 0.2854


Easy Hidden 0/3 68.7 KB
13 Answer sec

No comments.

Candidate Report Page 21 of 21

You might also like