JavaScript Interview Questions- Machine Coding - Most Asked Question
HTML-код
- Опубликовано: 24 авг 2024
- Javascript Interview Question on objects and Array will be discussed in this video .
Watch the complete video till the end to understand it completely
Checkout my Instagram account to find the latest notes on React, Angular and Javascript.
Instagram handler Name: @nishasingla05
Watch complete video to understand in depth.
Support my channel by liking and sharing my videos so that I can reach to wider audience. Please share it in your network 🙏
►Checkout JavaScript Interview Playlist
• Frontend Interview Que...
►Checkout ES6 Playlist
/ playlistlist=plc8okhrv...
►Click here to Subscribe the channel:
studio.youtube....
►Angular Complete Course:
ruclips.net/user/pl....
►All important shorts videos:
ruclips.net/user/pl....
Connect with Me On Social Media
Facebook: / angularjs4be. .
LinkedIn: / nisha-sin. .
Instagram : / nishasingla05
Twitter: / nishasingla05
#nishasingla #javascript #interview
Nice explanation. Thank you ❤
Should we use data.forEach instead of data.map as we are not concerned with return value of map function?
Wow such a nice explanation... I really liked your approach and logic... Thanks Nisha
Another way to do this:
const items = ["a", "b", "c", "a", "b", "b", "c", "d"];
const count = {};
for (const item of items) {
if (count[item]) {
count[item] += 1;
} else {
count[item] = 1;
}
}
console.log(count);
Nice Explanation
we can write using ternary operator like below
let ar = ['a','s','s','b','c','a','c','d','a','s'];
function arrOccurances(items){
let output = {};
items.forEach(item=>{
output[item] = output[item] ? output[item]+1 : 1
})
return output;
}
console.log(arrOccurances(ar));
(OR)
let ar = ['a','s','s','b','c','a','c','d','a','s'];
let output = {};
for(let item of ar){
output[item] = output[item] ? output[item]+1 : 1
}
console.log(output) ;
not only these ways, as Nisha said we have many ways to do it.
Thanks Nisha :-)
Thank u for the awesome video. Please continue react tutorial and complete the series.
Thanks for do this kind of videos
Thank you!!
well if you cant use map ,
let arr=['a','b','z','a','b','a','c']
let obj={};
for (let key in arr) {
console.log(obj[arr[key]],arr[key]); //undefined , a initially
obj[arr[key]]?obj[arr[key]]=obj[arr[key]]+1:obj[arr[key]]=1;
}
console.log(obj)
{
a: 3,
b: 2,
c: 1,
z: 1
}
last line of code is repeated , so simply we can write like below
obj[arr[key]] = obj[arr[key]] ? obj[arr[key]]+1 : 1;