20:00 we can also duplicate this array by using spread operators , const duplicate = (arr)=>{ return newArray = [...arr, ...arr] } console.log(duplicate([1, 2, 3])) It will return an new array
i had the same question back then, dont stress it , its pretty simple, when you use return , the data after it can be stored in a variable and can be accessed whenever you want, unlike consolelog , it just prints the data, whereas return stores it@@CreativKun
1:36:56 for most frequent item of array we can also do it very easily instead of using objects(by your method) use my method : function frequent(arr){ let ans = arr.reduce( (acc,num)=>{ return freq[acc] > freq[num] ? acc : num; }) console.log(ans); } frequent([1,2,3,4,1,4,3,1,3,7,])
very nice video broo ... for question 10 you can use reduce method also ,,,,const string='apple' const result = string.split('').reduce((acc,curr)=>{ if(acc[curr]){ acc[curr]= ++acc[curr]; }else{ acc[curr]=1; } return acc; },{}); console.log(result);
Hi Harsh brother - ur teaching style n the content u've provided hv been incredibly helpful 2 all of us. The way u explain complex concepts with clarity and enthusiasm truly makes a difference in our understanding.
Just a friendly reminder, during interview they expect you to use self made code. You can't use pre defined methods. Like sort, reverse etc. So prepare accordingly. All the best guys😁😁
And i did like this very small change but I understand better in this way: // shuffle an array const array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const shuffler = (arr) => { for (let i = arr.length - 1; i > 0; i--) { let rendomIndex = Math.floor(Math.random() * arr.length) let temp = arr[i] arr[i] = arr[rendomIndex] arr[rendomIndex] = temp } return arr } console.log(shuffler(array));
// shuffle given array function shuffleArray() { let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; arr.sort((a, b) => Math.random() - 0.5); console.log(arr); } shuffleArray(); this should also work
1:09:24 we can also use let arr=[ {name:"abcd",gender:"male"}, {name:"hrssfd",gender:"female"}, {name:"fsdfsd",gender:"female"} ] for(let i of arr){ if(i.gender !="male"){ continue; }else{ console.log(i) } }
your effors are well appreciated. Practising Javascript is the only way to become an good Frontend or even backend developer. But most of the times we learn ReactJs, Anglular any such frontend libraries is of no use. The more you practice, the better you will become.
Loop: add list of all members in array which is number. (ex: 4 or '4') Optimal Solution: Remember check all the edge cases. let members = [1,'fh','4','foo',5, '6']; const addMembers = members => { let count = 0; members.forEach(member => { if (!isNaN(Number(member))) { count += Number(member); } }) return count; } console.log(addMembers(members));
bhaiya can we do this also var array = [1, 2, 3, 4, 5, 6,7 ,8 ,9, 0]; var emptyArray = array.splice(array.length, array.length) console.log(emptyArray)
sir kya is question ko aise bhi kr sakte hain???? // 16. write a javascript function to get the last element of an array. Passing a // parameter 'n' will return the last 'n' element of the array // and should not come undefined value // function arr(e,n=2) // { // const res = e.reverse() // if(n
Sir please kuch questions ka solution bhut jada ghumane valla tha specially frequent element and shuffle valla pls sir in 2 programs ka koi simple solution bta dijiye.....baki sb smj a gya h ....and thankyou so much itna acha padane ke lieee
Because reverse method is for array it is not operate on string that's why we have to split string into a array then reverse it and join the array elements into string
function shuffleArray() { let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; for (let i=arr.length-1; i>0; i--) { let random = Math.floor(Math.random() * (i+1)); [arr[i], arr[random]] = [arr[random], arr[i]]; } console.log(arr); } shuffleArray(); this could be more easy & effective
function retrive(arr, ele = 1) { if (arr.length >= ele) { console.log(arr.slice(-ele)) }else{ console.log(`${ele} Elements nahi hai Arry me `) } } retrive([1, 2, 3, 4, 5, 6, 7], 1) print last elements
// Write a javascript program to compute the union of two arrays let newArr = [1,2,3,4,5,6,7,8,9,10]; let newArr2 = [9,10,11,12,13,14,15,16,17,18]; function union(arr1, arr2){ console.log([...new Set(arr1.concat(arr2))]); // return [...new Set(arr1.concat(arr2))]; } console.log(union(newArr, newArr2)); //Question : Why is there showing undefined showing in the output?
500 Likes and 150 comments ka target that for the next Questions video ab to Biya 6.3K likes and 318 Comments ho chukay hain so please continue this series ek alag playlist bnayn for Questions and bring more basic to advance JavaScript Questions on all JS topics, Thankyou.
Sir, Please make more questions like this it really help me a lot to undertstand the concept in so many other ways...................Waiting for more questions like this!!!!!!!!!!!
Question 4:- if you take number 0.1 it will give you Integer it will be failed in this situation any alternative approach ? If someone knows just drop ur logic ❤️
Thank you so much Harsh for putting together this important video! Really appreciate the hours of work you and your team put into recording/editing these videos all for free. Would like to support you by buying paid courses.
Sir , instead of using object to remove duplicate elements from an array can we convert first into set and then Array.from(set) by this way we got the array with unique numbers
Sir please make full course on html ,css, javascript, full stack developer course Please sir I like the way u teach !!! Please sir highly requested...🙇
Your teaching skill is amazing.... explore many things that are easy but never thing on that way...bus aap problem solve karte joke karte ho... usme aisa lagta he k jaise koi lorry driver drive karte karte joke mar raha he... 😂😂😂
Sir aap explain bahut achese kar rahe hain but jo background sound hai wo thoda sa disturb kar rhi hai concentrate hoke sunne me... Aapne bahut achi tarah se samjhaye hai problems mujhe saare samjh aaye per sound ne thoda sa problem diya other wise 10/9 .1 marks for sound
bhai muze laga Q.5. ka ans mai solve kr sakta hu to maine solve kiya but aapka ans dekhkr meri shakal 😳 . my Ans. - function duplicate(val){ var sampl = []; for(let i=0; i
/* 11:: Write a JavaScript function to get the first element of an array. Passing a barameter 'n' will return the first 'n' elements of the array. */ const retrieveNthFirstEle = (arr = [], n = 1) => { if (arr.length === 0 || n { if (arr.length === 0 || n = arr.length) return arr return arr.slice(-n); } console.log(retrieveNthLastEle([1,2,3,4,5,6,7], 2))
Thank you So much for providing such a good type of stuff. You and your team have proved to be the best teachers on the RUclips I ever seen on. One Of my little request, please make a video on the Flutter Development For beginners. ❤😊...
hey sir in the question where u counted non males and removing those objects, why didn't u break the loop once u deleted the first non male in the array, its confusing me
20:00 we can also duplicate this array by using spread operators ,
const duplicate = (arr)=>{
return newArray = [...arr, ...arr]
}
console.log(duplicate([1, 2, 3]))
It will return an new array
can you explain me What return Keyword Do???
@@CreativKunThe return keyword returns the value where the function is called.
i had the same question back then, dont stress it , its pretty simple, when you use return , the data after it can be stored in a variable and can be accessed whenever you want, unlike consolelog , it just prints the data, whereas return stores it@@CreativKun
@@kaushikbora2728 Thanks a lot
Hi sir please upload for complete javascript course I like your teaching style.
I also feel the same, solving complex problems very easily sir✨
It's already there. check their playlist it's LIT🔥
1:22:00 we can also use
function retrieve(arr, n = 1){
return arr.slice(0,n);
}
1:36:56 for most frequent item of array we can also do it very easily instead of using objects(by your method) use my method :
function frequent(arr){
let ans = arr.reduce( (acc,num)=>{
return freq[acc] > freq[num] ? acc : num;
})
console.log(ans);
}
frequent([1,2,3,4,1,4,3,1,3,7,])
very nice video broo ... for question 10 you can use reduce method also ,,,,const string='apple'
const result = string.split('').reduce((acc,curr)=>{
if(acc[curr]){
acc[curr]= ++acc[curr];
}else{
acc[curr]=1;
}
return acc;
},{});
console.log(result);
Q5 : => 2 method
let a = [1,2,3,];
console.log(a += a)
1:12:50
for(i=0;i
for (let j = arr.length - 1; j >= 0; j--) {
if (arr[j].gender !== 'male') {
arr.splice(j, 1);
}
}
-> also we can do like this..
Hi Harsh brother - ur teaching style n the content u've provided hv been incredibly helpful 2 all of us. The way u explain complex concepts with clarity and enthusiasm truly makes a difference in our understanding.
1:16:56
We Can also clone like this..
function cloneArr(data){
return data.map((e) => e)
}
console.log(cloneArr([1,2,3,4,5]));
37th question can be done in a single for loop
for(var i=0; i
agar ham ye use karenge to agar do consecutive females aayi to doosra vala object check hi nhi hoga
Array 10: Return data types: check all the corner cases.
const returnDataType = (variable) => {
if (typeof variable === 'object') {
if (Array.isArray(variable)) return 'array';
if (variable === null) return null;
return 'object'
}
return typeof variable;
}
console.log(returnDataType(function(){}))
For male question we can do it in single loop for(let i = arr.length-1 ; i >=0; i--){
If condition here
}
Just a friendly reminder, during interview they expect you to use self made code. You can't use pre defined methods. Like sort, reverse etc. So prepare accordingly. All the best guys😁😁
give me more tips brother
That's totally true.
And i did like this very small change but I understand better in this way:
// shuffle an array
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const shuffler = (arr) => {
for (let i = arr.length - 1; i > 0; i--) {
let rendomIndex = Math.floor(Math.random() * arr.length)
let temp = arr[i]
arr[i] = arr[rendomIndex]
arr[rendomIndex] = temp
}
return arr
}
console.log(shuffler(array));
// shuffle given array
function shuffleArray() {
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
arr.sort((a, b) => Math.random() - 0.5);
console.log(arr);
}
shuffleArray();
this should also work
Hi Harsh, Question - program to find frequent number is tough & hard to understand, so how can i solve it.
Q. Loop an array and all all elem in it..
arr.map((ele) => {
sum+= ele;
})
console.log(sum)
This is very helpful !!
Thankyou so much ❤️
yes..
It's literally mind-blowing 🤯🤯🤯🤯...
Please one more video same as it is🔥🔥🔥🔥,
like a interview problem solving... 😍😍😍
Shuffle array question answer in more smaller way
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
arr.sort(() => Math.random() - 0.5);
console.log(`Shuffled array: ${arr}`);
1:09:24 we can also use
let arr=[
{name:"abcd",gender:"male"},
{name:"hrssfd",gender:"female"},
{name:"fsdfsd",gender:"female"}
]
for(let i of arr){
if(i.gender !="male"){
continue;
}else{
console.log(i)
}
}
I used arr.splice(0) to empty the array.
Got to know today that it's can be done by setting array length to 0 also😊
retrun values.forEach(function(obj, index, arr) {
if (obj.gender=== "male") {
arr.splice(index, 1);
}
your effors are well appreciated. Practising Javascript is the only way to become an good Frontend or even backend developer. But most of the times we learn ReactJs, Anglular any such frontend libraries is of no use. The more you practice, the better you will become.
Loop: add list of all members in array which is number. (ex: 4 or '4')
Optimal Solution: Remember check all the edge cases.
let members = [1,'fh','4','foo',5, '6'];
const addMembers = members => {
let count = 0;
members.forEach(member => {
if (!isNaN(Number(member))) {
count += Number(member);
}
})
return count;
}
console.log(addMembers(members));
bhaiya can we do this also
var array = [1, 2, 3, 4, 5, 6,7 ,8 ,9, 0];
var emptyArray = array.splice(array.length, array.length)
console.log(emptyArray)
sir kya is question ko aise bhi kr sakte hain????
// 16. write a javascript function to get the last element of an array. Passing a
// parameter 'n' will return the last 'n' element of the array
// and should not come undefined value
// function arr(e,n=2)
// {
// const res = e.reverse()
// if(n
Thanks bro now I have mastered JavaScript as well as Persian 🛐
19:40 the way he said 'Chauuuda'
1:36:55 in the question to find most frequent item of array, how to solve it if more than one value occurs most time?
please replay
Please upload some more videos like this by taking some kor difficult problems using Javascript
Are sir please aise videos aur Lao js ki intuition build ho rhi hai meri aj phli bar sare questions aa gye
1:06:14 !!! brilliant answer type
For Genders Question (Using Filter First and then For Loop):::::::::::for (var j = 0; j < arr.length; ) {
if (arr[j].gender !== 'male') {
arr.splice(j, 1);
} else {
j++;
}
}
sir ye sahi hai question no 3=> let arr=[1,2,3,4,5,6,5,6,7,8]
let a=arr.splice(0,arr.length)
console.log(arr)
Sir please kuch questions ka solution bhut jada ghumane valla tha specially frequent element and shuffle valla pls sir in 2 programs ka koi simple solution bta dijiye.....baki sb smj a gya h ....and thankyou so much itna acha padane ke lieee
Please make some more videos,
It was very help full !important
Very well explained, waiting for next 20 questions 🙌🏻🙌🏻
Maazaa agaya bhaiyaa!
Just had a req, that pls avoid any background music henceforth. It becomes irritating at a certain point
Because reverse method is for array it is not operate on string that's why we have to split string into a array then reverse it and join the array elements into string
function shuffleArray() {
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
for (let i=arr.length-1; i>0; i--) {
let random = Math.floor(Math.random() * (i+1));
[arr[i], arr[random]] = [arr[random], arr[i]];
}
console.log(arr);
}
shuffleArray();
this could be more easy & effective
function retrive(arr, ele = 1) {
if (arr.length >= ele) {
console.log(arr.slice(-ele))
}else{
console.log(`${ele} Elements nahi hai Arry me `)
}
}
retrive([1, 2, 3, 4, 5, 6, 7], 1)
print last elements
Aap boht hi acchese simple language me smjhate ho..Loved it❤️❤️
That Background Music Make this Much Easier To understand....that is the we want to learn whole Video is Just awosome Great Explaination...
1:02:18
question removing object all object which gender != male
another solution
let people = [
{ name: "John", gender: "Male" },
{ name: "deepak", gender: 'undefind'},
{ name: "Emma", gender: "Female" },
{ name: "Alex", gender: "Male" },
{ name: "Sophia", gender: "Female" }
];
for(let i=0; i
harsh bhaiya ki teaching style❤ koi banda ubb hi nhi skta pdhte time😄
Thank you for your teaching style-it makes everything much easier to understand. 😊
Bhaiya JS me chrome k devloper tools me debug functionality kis tarah se use ki jati hai ek video banao. cover what are breakpoints.
background me jo music bjta hai ekdum slow me kaafi relaxing lagta hai aapne saare videos me daalo bhaya..
THANK YOU SO MUCH SIR...... HUGE RESPECT 50% QUESTIONS I DID IT...
// Write a javascript program to compute the union of two arrays
let newArr = [1,2,3,4,5,6,7,8,9,10];
let newArr2 = [9,10,11,12,13,14,15,16,17,18];
function union(arr1, arr2){
console.log([...new Set(arr1.concat(arr2))]);
// return [...new Set(arr1.concat(arr2))];
}
console.log(union(newArr, newArr2));
//Question : Why is there showing undefined showing in the output?
One output is perfectly showing but another is undefined, What is the error?
Why commented the return statement? uncomment it, will work.
8:15
Nimdaaa
Dosrass Sthelmi
Hardha-vhush KKRRAAK viku Nim-bhumla
Mohina ZukOOO...
Loha -KhuvAAA...
var str="hello sreehari how are you"
var reverseStr=(str.split("").reverse("").join(""));
console.log(reverseStr);
What about string
Ex.- var a ="12"
Then also its giving integer
500 Likes and 150 comments ka target that for the next Questions video ab to Biya 6.3K likes and 318 Comments ho chukay hain so please continue this series ek alag playlist bnayn for Questions and bring more basic to advance JavaScript Questions on all JS topics, Thankyou.
sir please make this type of videos more it's help lot...... Thank you so much sir😇😇😇😇😇😇😇
Sir, Please make more questions like this it really help me a lot to undertstand the concept in so many other ways...................Waiting for more questions like this!!!!!!!!!!!
Really appreciate your efforts...thankss
btw part 2 wasn't posted ?
Question 4:- if you take number 0.1 it will give you Integer it will be failed in this situation any alternative approach ? If someone knows just drop ur logic ❤️
Hi Harsh
Can you please provide the doc which has only questions in it so that we can practice and see the solution
Thanks
well a wonderfull journey of 2 hours come to an end it was worth it to watch and follow u thanks once again
Problem number 3 solution:
function emptyArray(arr) {
return arr.filter((item) => !item);
}
console.log(emptyArray([1, 5, 8, 63]));
Harsh Bhai, the way you teach is awesome, only I am distracted watching you when you adjust your glasses 👓 every15 secondsc.
Thank you so much Harsh for putting together this important video! Really appreciate the hours of work you and your team put into recording/editing these videos all for free. Would like to support you by buying paid courses.
Sir , instead of using object to remove duplicate elements from an array can we convert first into set and then Array.from(set) by this way we got the array with unique numbers
Bahi you are amazing ..Love from Hyderabad Please Keep helping us bahi in our web development journey❤
Sir please make full course on html ,css, javascript, full stack developer course
Please sir
I like the way u teach !!!
Please sir highly requested...🙇
Your teaching skill is amazing.... explore many things that are easy but never thing on that way...bus aap problem solve karte joke karte ho... usme aisa lagta he k jaise koi lorry driver drive karte karte joke mar raha he... 😂😂😂
most amazing question series omg this is just wow ; the explanation of bhaiya was truly amazing loved it bhaiya genuinely loved it
ab ese kehte hai sikhana pura explain karke thank you bhaiya....
1:16:10 can't we just use
return arr;
Love you sir job lg gyi to phle salary se apka hi course kharidunga
This teach styles and explanation is awesome 😮❤
Sir aap explain bahut achese kar rahe hain but jo background sound hai wo thoda sa disturb kar rhi hai concentrate hoke sunne me... Aapne bahut achi tarah se samjhaye hai problems mujhe saare samjh aaye per sound ne thoda sa problem diya other wise 10/9 .1 marks for sound
Sir please help meri js work nhi kr rha hi hai q ko console me uncaught typeerror: cannot read Properties is first. Js:4 null ( read getaatribute)
easy and hard at same time . but sara smj agaya bohut achiy sa smjhty hn ap
make a path, write in 30 points the interview questions from easy to difficult of the javascripts programming language
hi brother i want to some little favour of your. Javascript problem in php. can you help to solve this?
Reverse Number:: Including negative value
function reverseNumber(num) {
let reversed = 0;
let sign = Math.sign(num);
num = Math.abs(num);
while (num > 0) {
reversed = reversed * 10 + num%10;
num = Math.floor(num / 10);
}
return reversed * sign;
}
console.log(reverseNumber(-12300)); // -321
console.log(reverseNumber(123)); // 321
console.log(reverseNumber(450000)); // 54
Bro Dot Net development Ka Tutorial Lao Please Project ke sath
More optimal solution for gender based filter:
General filter:
const filterByGender = (users, gendersToFilter) => {
return users.filter(user => gendersToFilter.includes(user.gender))
}
console.log(filterByGender(users, ['male']))
Solution for Exclude:
const filterByGenderExcept = (users, gendersToExclude) => {
return users.filter(user => !gendersToExclude.includes(user.gender))
}
const users = [
{ name: 'abc', gender: 'male'},
{ name: 'cc', gender: 'female'},
{ name: 'bb', gender: 'any'},
{ name: 'dd', gender: 'female'}
]
console.log(filterByGenderExcept(users, ['male']))
bhai muze laga Q.5. ka ans mai solve kr sakta hu to maine solve kiya but aapka ans dekhkr meri shakal 😳
.
my Ans. -
function duplicate(val){
var sampl = [];
for(let i=0; i
Question 1: advanced solution with Palindrome problem.
const removeSpaceFromString = str => str.replace(/\s/g, '')
const reverse = str => str.split('').reverse().join('');
const ispalindrom = str => {
const isString = (typeof str === 'number') ? str.toString() : str;
const valueWithoutSpace = removeSpaceFromString(isString)
return (valueWithoutSpace === (reverse(valueWithoutSpace))) ? 'Palindrome' : 'Not Palindrome'
}
console.log(ispalindrom('m a m')) //Palindrome
console.log(ispalindrom(5.5)) // Palindrome
console.log(ispalindrom('deified')) // Palindrome
/* 11:: Write a JavaScript function to get the first element of an array. Passing a barameter 'n' will return the first 'n' elements of the array. */
const retrieveNthFirstEle = (arr = [], n = 1) => {
if (arr.length === 0 || n {
if (arr.length === 0 || n = arr.length) return arr
return arr.slice(-n);
}
console.log(retrieveNthLastEle([1,2,3,4,5,6,7], 2))
thank you so much sir. It helped a lot.
can you make more video like this for javascript question it's amazing video
20 more questions needed btw amazing video❤🔥
aage ke questions konsi video me hai?
we need more video like this plssss continue
25:25 agar hum 12340 pass kren then 4321 ata ha " 0 " value ni ati
What if we have to concatenate more than two times?
Thank you So much for providing such a good type of stuff. You and your team have proved to be the best teachers on the RUclips I ever seen on.
One Of my little request, please make a video on the Flutter Development For beginners. ❤😊...
Hi Harsh brother. Kindly make some more videos on JS interview questions.
This is very helpful !!
Thankyou so much ❤
that's great teacher and well teaching method keep it up brother
awesome questions and teching style.
let arr = [1,2,3,4]
console.dir(arr);
Hum Jo html form banate hain usko submit karne ke baad uska data humare email par ana chahiye kaise kar shakte hain
Thankyou For This Lessons Sir
hey sir in the question where u counted non males and removing those objects, why didn't u break the loop once u deleted the first non male in the array, its confusing me