JavaScript Mock Interview | Online Interview | Questions and Answers

preview_player
Показать описание
Online Front End Phone Interview recorded live with questions on JavaScript , Algorithms and Problem Solving with suggestions. interview practice. Practice javaScript

#Mock #JavaScript #Interview

If you like to be mock interviewed, email me at

*My Udemy Courses

Follow me for technology updates

Help me translate this video.
Рекомендации по теме
Комментарии
Автор

My answer for the first question
const addMemberAge = ({ age, kids = [] }) =>
[age]

.reduce((accumulator, currentValue) => accumulator + currentValue);

sundargp
Автор

Good questions. Thank you for uploading.

sandeepreddy
Автор

No offense to the interviewee, but I really wouldn't really start an answer to TechSith's questions with "it's a very simple question" :)
Anyways, a potential recursive answer to the first question: (should be able to handle ages as keys or within nested arrays, objects etc )
function getSum(obj, sum = 0) {
if(Array.isArray(obj)) {
for(let ele of obj) {
sum = getSum(ele, sum)
}
} else if(typeof obj === 'object') {
for(let key in obj) {
if(typeof obj[key] !== 'object') {
if(key === 'age') {
sum = sum + obj[key]
}
} else {
sum = getSum(obj[key], sum)
}
}
}


return sum
}

maheshsingh
Автор

The first problem is just flat a tree. Using recursion is the first thing that pops into my head. However you can run away from the problem by using JSON.stringify, then all there left to do is analyse the json string, kind of like cheating

patrickren
Автор

A "neater" recursive solution to question 1:

function addKidAge(kids) {
let kidTotalAge = 0;

for(const kid of kids) {
kidTotalAge += kid.age;

if(kid?.kids?.length > 0) {
kidTotalAge += addKidAge(kid.kids);
}
}

return kidTotalAge;
}

To run it, just do addKidAge([profile])
Notice that the profile object is inside an array :)

ozzyfromspace
Автор

function totalAge({age, kids=[]}){
return kids.reduce((sum, kid)=> sum + totalAge(kid), age )
}


//Use reduce

vikasraju
Автор

2 yr exp solved all of them within 5mins, no google

vikrantgupta
Автор

Can you make a video on career path in IT field...

Thankyou for all your react and javascript videos,
with best and simple way of explaining things.

hari
Автор

It only took me 367 tries but I finally solved the first problem. (Feel free to suggest improvements.)

function addUpAges(profile) {
let total = 0;

function addUp(profile) {
total += profile.age || 0;
if (!profile.kids)
return;
return profile.kids.forEach(addUp);
}
addUp(profile);

return total;
}

maelstrom
Автор

I'm just starting out in coding with Javascript...

But regardless of coding language being used, I think it might be more efficient to write stubs & pseudo code first, explaining what your doing and why verbally as you stub it out...

Once psuedo code makes sense, then write corresponding code for each stub...

If one just jumps in and starts coding, even if one gets it correct first time, there's very lil interaction with interviewer....

Just a thought...

I've always been of mindset that if one cannot explain it, then they don't really understand it...

Plus during an interview psuedo coding & stubbing it as you explain gives interviewer an idea of your thought process and opportunity to explain as you're writing pseudo code why ( your rationale ) for implementing something a particular way...

I'm not a professional programmer. I'm working on becoming one...


Thanks for sharing video

Thankful_n_Grateful
Автор

The first problem can be solved with one line. Easy
JSON.stringify(profile).match(/\d+/gi).reduce((a, c) => {return a + parseInt(c)}, 0)

Chessmasteroo
Автор

This SHOULD be a bulletproof solution to the first problem! Accounts for when some ages don't exist

const addAllAges = (profile) => {
if return 0;

let totalAge = profile.age || 0;

for (let kid of profile.kids) {
if (kid.age === undefined) continue;

if (kid.kids !== undefined) {
totalAge += addAllAges(kid);
} else {
totalAge += kid.age;
}
}

return totalAge;
}

ChaoticBlackout
Автор

Can you direct me to video tutorial you're explaining these concepts deeply ? Thank you

mayow
Автор

Can you recommend a good GIT and GIThub course

ickimadrasi
Автор

Hi, I have asked to write code for write in ballots using JavaScript in my interview

vadivelraja
Автор

hi techsit interviewer asked prime no program n no asked me optmize for loop for n=3000 for(i=0;i<n;;i++)

MohdAfeef
Автор

my answer for 2nd problem:

function que(){

let first = Math.floor(Math.random() * Math.floor(10));
let sec = Math.floor(Math.random() * Math.floor(10-first));



}
for(let i=0;i<5;i++){
que();
}

ManojSingh-ofep
Автор

asked me api has currency, value store value ony db by api request should not repeat for currency he told me solution 1/1, 2/2 diagonal matrix solution for this problem

MohdAfeef
Автор

my simple solution for the second problem. can i use a function that accepts 2 arguments?

function game(num, num2){
for(var i =0; i<5; i++){
var one = Math.floor(Math.random() * num)
var two = Math.floor(Math.random() * num2)
result = +one + "+" + two + "=";
console.log(result)
}
}


game(10, 10)

orz
Автор

last problem solution :


const generateRandomNumber = (max, min = 1) => {
return Math.floor(Math.random() * (max - min) + min);
};
const generateProblems = (max, n) => {
for (let i = 0; i < n; i++) {
const firstRandomNumber = generateRandomNumber(max);
console.log(
`${firstRandomNumber} + ${generateRandomNumber(
max - firstRandomNumber
)} = `
);
}
};

assamaafzal