Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

35 Commits

Repository files navigation

Debugging skill exam

Exercise 1: Infinite Loop (3 Minutes)

Description: The following pseudo code is intended to print numbers from 1 to 10, but it runs indefinitely. Identify and fix the issue.

functionprintNumbers(){leti=1letj=0while(i<=10){console.log(i)j++}}

Challenge: Fix the loop so it terminates correctly.


Exercise 2: Understanding Function Composition, Loop Logic, and Conditional Execution (5 Minutes)

Description: Find the final value of ans by tracing the code step-by-step,

f=(x)=>2*xg=(y)=>3*y+1ans=0result=0n=2for(i=1;i<5;i++){result=ans*2||2}while(n>0){ans=g(ans)n=n-2}if(f(2)<g(0)){ans=g(0)+result}

Exercise 3: Class (3 Minutes)

Consider the file ab.js

exportclassA{constructor(){this.x=0}increment(){return++this.x}}constnewA=newA()exportconsta=newAexportfunctionmakeA(){returnnewA()}

then file main.js

import{a,makeA}from"./ab.js"functionexecute(){constb=makeA()console.log(a.increment())console.log(b.increment())}execute()execute()

what is output result of second execute()

Exercise 4: Scaling our service (3 Minutes)

We are trying to scale this Express service

queue.consume(msg=>{sendSMS(msg)})cron(*12***){sendEmail()}app.get('/service',async(req,res)=>{return ...
})

Are there any problem if we install load balancer and scale this service from 1 to 4 instances

Exercise 5: Error Handling and Synchronous (3 Minutes)

constf=()=>{thrownewError("X")}constg=()=>{Promise.resolve().then(()=>{console.log("E")thrownewError("F")}).finally(()=>{thrownewError("G")})}console.log("A")try{f()console.log("B")}catch{console.log("C")}console.log("D")try{g()thrownewError("H")}catch{console.log("I")thrownewError("J")}console.log("K")

What is the output printed to console

Exercise 6:

let's assume that we have some dummy bank account service

letbalance=0functiondeposit(x){returnnewPromise(resolve=>setTimeout(()=>{balance+=x;resolve(balance)},Math.random()*10))}functionwithdraw(x){returnnewPromise(resolve=>setTimeout(()=>{if(balance>=x)balance-=x;resolve(balance)},Math.random()*10))}constresult=awaitPromise.all([deposit(100),deposit(20),withdraw(120),])console.log("balance:",balance)

What is the output?

About

Debugging skill exam

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Contributors