The one you mentioned for sorting is not working. Instead of returning ab it should be a-b or b-a in the call back function. Thank you for this video :)
Yes, you are right, because the callback function does not return boolean value! It has to return an Integer value (negative, zero or positive). For example, if you want to sort a number's array, you have to write down the callback function something like that : [2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? -1 : (elt1 === elt2 ? 0 : 1)}); // ascending way Output => [2, 3, 8, 43, 56, 467] [2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? 1 : (elt1 === elt2 ? 0 : -1)}); // ascending way Output => [467, 56, 43, 8, 3, 2]
Also worth mentioning. You can turn it into a ternary statement using the ? : Syntax, like a < b ? 1 : -1 Then it will return the proper sorting (least to greatest). Or change the above to > sign for same thing but will sort greatest to least. If they are equal then not sure what will happen though because it should be 0 in the case.
Thank you so much for making the videos and helping the web developers careers. For some reason, the sorting of integers with callback didn't work with a
For the sorting one, the comparison is not working because the function looks for a number value, not a boolean :( x.sort((a,b) => (a-b)) works though! Thanks for this though and I love your videos
If an interviewer asks you these questions, just leave the interview because there are tonnes of things to ask about code management, design patterns and consideration of scalability.
Yes, interviewer ask me to solve sum(1)(2)(3) //ans =6.. im really confused after this ques they ask me easy ques but could not answer it because of 1st ques
Interviewers are asking these questions just to see how you could understand JS. It won't be major part of the interview and they expect you to answer them less than 5 min.
I am too late with homework, but NaN === NaN is false because NaN is typeof Number which is an object (not primitive). When you compare objects in JavaScript, you are determining if 2 objects are the same instance of specified object type. So you are comparing 2 different instances of Number object. For example undefined === undefined is true, because undefined is primitive type (you are just comparing values). And seems like my answer is wrong 😅
Well i guess u r half correct, NaN is non-primitive object and 2 non primitive objects arent equal to each other because they are stored at a different memory heap...
Just a note as a mathematician - 0/0 is undefined mathematically, rather than infinite (think: anything multiplied by 0 is 0, but anything divided by 0 is infinite, so 0/0 doesn't have any value). When we have i = MIN_VALUE, i*i is 0 because i*i is less than i, so js makes it zero (as appears to be the definition of MIN_VALUE). And then i/i is 1 not because i is small, but just because anything divided by itself is one (except 0/0).
Thanks for the Q&A!! Really love the videos. For the problem [1, 2, 3] + [4, 5, 6] how come the "[" and "]" were ignored but not the commas "," during concatenation?
Yes, you are right, because the callback function does not return boolean value! It has to return an Integer value (negative, zero or positive). For example, if you want to sort a number's array, you have to write down the callback function something like that : [2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? -1 : (elt1 === elt2 ? 0 : 1)}); // ascending way Output => [2, 3, 8, 43, 56, 467] [2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? 1 : (elt1 === elt2 ? 0 : -1)}); // ascending way Output => [467, 56, 43, 8, 3, 2]
You have to use the diffing of the comparison for the sort method. It won't work if you don't. console.log('answer:', arrayList.sort((a, b) => { return a - b; }));
When you said 0/0 is infinite, it's not true. It's always NaN in JavaScript. And it's not infinite in Mathematics either. Your videos are great source of learning. Thank you for making time and making these ones 🙂.
Sorting is not working, the return must be a-b for Ascending and b-a for descending order console.log(a.sort((a,b)=>{return a-b})); // Asc console.log(a.sort((a,b)=>{return b-a})); // Desc
NaN is not a specific value it is just saying that that particular value is not a number hence the value of NaN need not to be same so it returns false if compare NaN with NaN using == or ===
False NaN is short for not a number and I think the reason NaN === NaN is false is it might be different opertaions like 2/0 or √-7.both of them are NaN but the opertaion numbers are different
Gonna answer honest for my thought on NaN === NaN... The result of it must be false (otherwise there is no point in question) :) I read about it, I gues it was in "You think you know JS", I think its just made that way couse NaN could be an expression for a lot of things, thats all I have :D
This is interesting, but as someone has already said in the comments, if I was asked some of these questions in an interview I would walk out the door...
Yes, you are right, because the callback function does not return boolean value! It has to return an Integer value (negative, zero or positive). For example, if you want to sort a number's array, you have to write down the callback function something like that : [2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? -1 : (elt1 === elt2 ? 0 : 1)}); // ascending way Output => [2, 3, 8, 43, 56, 467] [2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? 1 : (elt1 === elt2 ? 0 : -1)}); // ascending way Output => [467, 56, 43, 8, 3, 2]
NaN compared to anything is always false.However, Here comes the interesting stuff (typeof null is an Object and type of Object is also Object. When you do a "==" with both of them, it will return you a false.
First of all let me say thumbs up and I am already subscribed of course with notifications turned on! Thanks for taking the time to make another educational and fun video and share it with all of us! I am on my phone so I cannot test your final homework, it feels like it should be a truthy question and normally I would say in this case it should evaluate to true, however since you are trying to trick us, somehow I bet it is false? Is something weird with NaN?
You guessed it right. it is false . that is becase NaN compares unequal (via ==, !=, ===, and !==) to any other value -- including to another NaN value.
sir , i have one question. Actually i was asked this question in interview. the question is about converting normal javascrpt function to call back function... so question goes like this,... function aa(){ return 1; } var res = aa(); so they wanted me to convert above function into call back function.. how to do sir ? plz help
hello sir can you tell me what should i learn i mean the things i really need so i can move on to js frameworks ? i would love if you make some simple realtime projects using js and thanks for the awesome videos !
If a programmer asks this "trick question" in an interview, I get up and leave. All to the fact that NO ONE will dare write this type of shit and commit this code, it's unreadable, unrelated and confusing, if you would like to return (-1) from your array, there are a myriad of SIMPLE AND READABLE ways to do it. The only thing I could think he's trying to gain out of this is him trying to show me that he knows how to be a good QA, nothing more.
It’s just a question so to challenge your understand of how es6 gets compiled. It’s one thing to “know that” the behavior of an operation returns an output, but it’s best practice to “know how”, epistemologically speaking. These challenges are just a glimpse into how powerful js can get. Sure, you will not see code written as such because it doesn’t follow the object-oriented principal of being semantic as possible.
@@treyrader OK, you seem like quite a learned individual, and I think I understand your point about OO semantics, but I would argue that JavaScript's OO epistemology -- the actual overarching theme of this video -- is actually "synthetical sugar." I believe you may be referring to Typescript, which as you may know, is a superset of JS. Please correct me if I'm mistaken.
@@Alexanderthenotsobad Hey man, sorry for the late reply as I am just now seeing the notification. I think you are correct that perhaps I was referring to typescript, albeit inadvertently. In truth, my knowledge of web concepts and of JS is, comparativelys peaking, pretty far from vast. This explains why I am on youtube watching tutorials on it as well as why I had to look up the concept of "Typescript.". All that I was trying to express though in my prev comment is that the questions prompted in this mock interview are just a tool for the person conducting the interveiw to assess your ability to problem solve. It makes sense to me that the questions in the end of the interview would seem almost irrevelant and entirely unorthodox to the convention of standard coding so to ensure that they aren't rotely memorized. Were the interviewee to get these correct, surely it'll exceed the expectations of the interveiw and thus ensure that he or she is a spectacular candidate. Cheers!
write code to display even number s from 20 to zero using the Do-While loop Javascript This is my code its not correct, I need some help please var i = 0; var n = Number(window.prompt("Enter any number : ")); do{ i--; document.write("Number is = " + i + ""); }while(i
Please you said in minute 03:00 that you will provide a link of negative index video in Javascript so where is the link of the negative index in Javascript video?!
Hello sir In interview i was get ask for the below question and expected result part of array convert string . Question var sampleArry = [1,2,3 {a:4, 5} 6, 7 , 8, [9,10] ] Expected [1,2,3,4,5,6,7,8,9,10] Can you please explain how to fix it. In question of array there is tricky part of object in side of array which is not canvter as a string. Kindly reply
05:25 I don't seem to get it to work by using return a > b. Weird thing is that if I return a - b then it works properly. Am I doing something wrong? Thank you in advance. const arr = [1, 2, 15, 30, 5, 45, 7]; console.log(arr.sort((a, b) => { return a - b; }));
@@Techsithtube I made a fiddle in which I console log the example you used in this video that isn't working for me. jsfiddle.net/2yr69pn7/ I'm really confused why the minus sign is doing the sort correctly but the less/greater than sign isn't. Thank you for the instant reply! That caught me off guard haha :D
video is great but HR would not ask so many tricky and meaningless question for one student. Such question based on concepts but far away from the real world
11:05 - the weirdest part is if you console.log 17 fives it will return 55555555555555550. Shouldn't it have "..60" on the right? And console.log(44444444444444444); gives us this: 44444444444444450. Doesn't make any sense =)
techsith, I am still having doubt. Why it wasn't like 55555555555555560 with 5's similar to 44444444444444450 with 4's. I know, after 16 digits, it's all absurd but with others, we see that 16th digit increments and further digits truncates to 0s. Please clear me also on this. Anyways, I liked this video a lot. Keep going!
JS is confusing for programmes from other languages. First of all its nonblocking and second of all it has lots of weird things that you can still use it but you shouldn't. I would suggest to learn only latest JavaScript .
This is an Interview question. Can anyone explain the answer why when using for loop inside "var" 10 times iterating and showing undefined and when using "let" for loop inside getting the 1,2,3,..., 10. const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; for (var i = 0; i < 10; i++) { setTimeout(() => console.log(a[i]), 1000); }
Hello Sir, i try same but i get wrong result ... const ary = [1,21,334,44,2,3,4,5,667,7,8,80,55]; alert(ary.sort()); alert(ary.sort((a,b) => { return a < b; })) alert(ary.sort((a,b) => { return a > b; })) what's wrong here...
Hi, Could you tell me Y this result is coming in my console? var i = Number.MIN_VALUE; console.log(i); console.log(i+i); console.log(i-i); console.log(i*i); console.log(i/i); VM173:2 5e-324 VM173:3 1e-323 VM173:4 0 VM173:5 0 VM173:6 1
THere is a MIN_VALUE in javaScript that is the smallest possible number. and adding one to it changes that number slightly. removing from the smallest number should make it a 0 same with multiplication. however, dividing the same number should give you one.
The one you mentioned for sorting is not working. Instead of returning ab it should be a-b or b-a in the call back function. Thank you for this video :)
Thanks, I was reading the comments for this.
Yes, you are right, because the callback function does not return boolean value!
It has to return an Integer value (negative, zero or positive).
For example, if you want to sort a number's array, you have to write down the callback function something like that :
[2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? -1 : (elt1 === elt2 ? 0 : 1)}); // ascending way
Output => [2, 3, 8, 43, 56, 467]
[2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? 1 : (elt1 === elt2 ? 0 : -1)}); // ascending way
Output => [467, 56, 43, 8, 3, 2]
It works in Gecko...I mean firefox's engine...Doesn't work in V8...i.e. Chrome, Nodejs would give unexpected output
Also worth mentioning. You can turn it into a ternary statement using the ? : Syntax, like
a < b ? 1 : -1
Then it will return the proper sorting (least to greatest). Or change the above to > sign for same thing but will sort greatest to least. If they are equal then not sure what will happen though because it should be 0 in the case.
try a-b instead of a>b
Thank you so much for making the videos and helping the web developers careers.
For some reason, the sorting of integers with callback didn't work with a
For the sorting one, the comparison is not working because the function looks for a number value, not a boolean :(
x.sort((a,b) => (a-b)) works though!
Thanks for this though and I love your videos
I also bumped into this issue. (a-b) worked but (a
Exactly, and for descending order you would write x.sort((a, b) => b - a);
@@2dabang V8 doesn't support that, I guess, because Node also doesn't support a > b
If an interviewer asks you these questions, just leave the interview because there are tonnes of things to ask about code management, design patterns and consideration of scalability.
Yes, I agree. but sometimes people ask such questions and its unfortunate.
Yes, interviewer ask me to solve sum(1)(2)(3) //ans =6.. im really confused after this ques they ask me easy ques but could not answer it because of 1st ques
var i = 0;
function sum(n) {
i+=n;
return sum;
}
sum(1)(2)(3)(6);
console.log(i);
I learned from TechSith only. Function chaining.
Sure interviewer asks you these questions, it's really a great video.
Interviewers are asking these questions just to see how you could understand JS. It won't be major part of the interview and they expect you to answer them less than 5 min.
I am too late with homework, but NaN === NaN is false because NaN is typeof Number which is an object (not primitive). When you compare objects in JavaScript, you are determining if 2 objects are the same instance of specified object type.
So you are comparing 2 different instances of Number object.
For example undefined === undefined is true, because undefined is primitive type (you are just comparing values).
And seems like my answer is wrong 😅
It is right, good explanation!
@@alreadytakenindeed even if my explanation sounds like a true, you shouldn't believe. It was just my opinion.
Well i guess u r half correct, NaN is non-primitive object and 2 non primitive objects arent equal to each other because they are stored at a different memory heap...
The one you mentioned for sorting is not working. Instead of returning ab it should be a-b or b-a in the call back function.
NaN compared to anything is always false, even comparing to itself!
That is the right answer. :)
is there a point to memorizing this type of NaN trivial apart from this interviews. i mean one can always look it up in real life scenarios, no?
techsith hello sir .. can I have your email or contact number.. wanted to talk with you. Please let me know
But isNan(Nan) will be true;
isNan('hello') will be true
Number.isNan('hello;) will be false.
JS is killing me)
it is worth mentioning that when we use "use strict" it will throw the error (example with IIFE)
Just a note as a mathematician - 0/0 is undefined mathematically, rather than infinite (think: anything multiplied by 0 is 0, but anything divided by 0 is infinite, so 0/0 doesn't have any value). When we have i = MIN_VALUE, i*i is 0 because i*i is less than i, so js makes it zero (as appears to be the definition of MIN_VALUE). And then i/i is 1 not because i is small, but just because anything divided by itself is one (except 0/0).
Thanks for the Q&A!! Really love the videos. For the problem [1, 2, 3] + [4, 5, 6] how come the "[" and "]" were ignored but not the commas "," during concatenation?
yes because its JavaScript :) Basically it try to convert array to string.
var arr = [2,3,42,4,5,4,5,6,7,2,3]
, if we have an array like this
we cannot get expected results with '' operator
Yes, you are right, because the callback function does not return boolean value!
It has to return an Integer value (negative, zero or positive).
For example, if you want to sort a number's array, you have to write down the callback function something like that :
[2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? -1 : (elt1 === elt2 ? 0 : 1)}); // ascending way
Output => [2, 3, 8, 43, 56, 467]
[2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? 1 : (elt1 === elt2 ? 0 : -1)}); // ascending way
Output => [467, 56, 43, 8, 3, 2]
Your videos are great. They are short but covers a lot. Keep doing the great work 👍🏻
2:31 index doesn’t mean to find the value. Its like find me the location of that value.
You have to use the diffing of the comparison for the sort method. It won't work if you don't.
console.log('answer:', arrayList.sort((a, b) => {
return a - b;
}));
When you said 0/0 is infinite, it's not true. It's always NaN in JavaScript. And it's not infinite in Mathematics either. Your videos are great source of learning. Thank you for making time and making these ones 🙂.
console.log(55555555555555555555555)
I never seen this type of questions.
How do you find such a type of questions like this? This is awesome.🙂👍🏻
i was doing a project work and came across this issue related to 18 digit number
Thank you so much
We wanna a separate Playlist to all of the Tricky Javascript interview questions videos
p=[12, 2, 3, 33];
p.sort((a,b)=> {return Number(a) - Number(b);})
Easier this way... p.sort((a,b)=> {return a - b;})
Minus sign implicitly coerce them to Number;
Sorting is not working, the return must be a-b for Ascending and b-a for descending order
console.log(a.sort((a,b)=>{return a-b})); // Asc
console.log(a.sort((a,b)=>{return b-a})); // Desc
Another way of adding two arrays together and display them as a string is this: [1,2,3].concat([4,5,6]).toString()
NaN is not a specific value it is just saying that that particular value is not a number hence the value of NaN need not to be same so it returns false if compare NaN with NaN using == or ===
I feel much fun, enthusiastic while attempting these interview questions.Awesome stuff
I am glad its fun for you, I will make some more. :)
False
NaN is short for not a number and
I think the reason NaN === NaN is false is it might be different opertaions like 2/0 or √-7.both of them are NaN but the opertaion numbers are different
Use Number.isNaN(NaN) to compare it will return true
8:44 - wrong. MAX_VALUE multiplies to Infinity, not 0
Love the way you explain ❤
Gonna answer honest for my thought on NaN === NaN...
The result of it must be false (otherwise there is no point in question) :)
I read about it, I gues it was in "You think you know JS", I think its just made that way couse NaN could be an expression for a lot of things, thats all I have :D
Great Video as always :) Thanks for making JavaScript so easier to learn :) .
Thanks for watching harsh!
These are JS interview questions straight out of hell 🔥 😂
Thank you so much for your super insightful and quick videos! I love them
👍 cool experiments with js. thank you sir.
Here we go again.
I really enjoy these series. Thanks you sir!
This is interesting, but as someone has already said in the comments, if I was asked some of these questions in an interview I would walk out the door...
sorting is not working using arr.sort((a,b)=>{return a
Yes, you are right, because the callback function does not return boolean value!
It has to return an Integer value (negative, zero or positive).
For example, if you want to sort a number's array, you have to write down the callback function something like that :
[2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? -1 : (elt1 === elt2 ? 0 : 1)}); // ascending way
Output => [2, 3, 8, 43, 56, 467]
[2, 3, 43, 467, 56, 8].sort((elt1, elt2) => {return elt1 < elt2 ? 1 : (elt1 === elt2 ? 0 : -1)}); // ascending way
Output => [467, 56, 43, 8, 3, 2]
NaN compared to anything is always false.However, Here comes the interesting stuff (typeof null is an Object and type of Object is also Object. When you do a "==" with both of them, it will return you a false.
Correct!
I loved it, Can i have quations like this of angularJS 1.x as well?
I enjoy these JS questions videos.
I like that interview series. thanks!
console.log(NaN === NaN);it returns false,beacause we dont know what exactly number we are doing operations.:-)
First of all let me say thumbs up and I am already subscribed of course with notifications turned on! Thanks for taking the time to make another educational and fun video and share it with all of us! I am on my phone so I cannot test your final homework, it feels like it should be a truthy question and normally I would say in this case it should evaluate to true, however since you are trying to trick us, somehow I bet it is false? Is something weird with NaN?
You guessed it right. it is false . that is becase NaN compares unequal (via ==, !=, ===, and !==) to any other value -- including to another NaN value.
techsith this was fun, you should consider putting out one trick question or brain teaser every week
I don't understand why I have to write a callback to sort! I already provided array of integers! Totally unexpected!
more homeworks pls.. specially coding problems and interview tasks
i love your accent it's very clear!
Thank you :)
Very tricky and helpful!
sir , i have one question. Actually i was asked this question in interview. the question is about converting normal javascrpt function to call back function... so question goes like this,...
function aa(){
return 1;
}
var res = aa();
so they wanted me to convert above function into call back function.. how to do sir ? plz help
const aa = () => 1; It has to be explicitly declared to use as a callback.
@@flysports3856
var res= aa;
function test(cb){
if(typeof cb === 'function'){
let output = cb();
console.log(output);
}
}
test(bb);
This might help
I think we can do like this
function aa(b) {
console.log('sum is : ' + b);
}
function bb(a, b, cc) {
let x = a + b;
cc(x);
}
bb(1, 2, aa);
@@swetharedddysh Hi thank you so much . Your solution works well.
If Type(x) is Number, then
If x is NaN, return false.
If y is NaN, return false.
hello sir can you tell me what should i learn i mean the things i really need so i can move on to js frameworks ? i would love if you make some simple realtime projects using js and thanks for the awesome videos !
learn latest version of JavaScript don't try to learn old deprecated stuff and then pick a framework like react.
Nice video. Thanks for your hard work and time.
null===null give you true,NaN==NaN give false
You got it. Thanks for the response.
If a programmer asks this "trick question" in an interview, I get up and leave.
All to the fact that NO ONE will dare write this type of shit and commit this code, it's unreadable, unrelated and confusing, if you would like to return (-1) from your array, there are a myriad of SIMPLE AND READABLE ways to do it.
The only thing I could think he's trying to gain out of this is him trying to show me that he knows how to be a good QA, nothing more.
Agreed... The first few questions were valid, then he went off the rails.... GL2U
It’s just a question so to challenge your understand of how es6 gets compiled. It’s one thing to “know that” the behavior of an operation returns an output, but it’s best practice to “know how”, epistemologically speaking.
These challenges are just a glimpse into how powerful js can get. Sure, you will not see code written as such because it doesn’t follow the object-oriented principal of being semantic as possible.
@@treyrader OK, you seem like quite a learned individual, and I think I understand your point about OO semantics, but I would argue that JavaScript's OO epistemology -- the actual overarching theme of this video -- is actually "synthetical sugar."
I believe you may be referring to Typescript, which as you may know, is a superset of JS. Please correct me if I'm mistaken.
@@Alexanderthenotsobad Hey man, sorry for the late reply as I am just now seeing the notification.
I think you are correct that perhaps I was referring to typescript, albeit inadvertently. In truth, my knowledge of web concepts and of JS is, comparativelys peaking, pretty far from vast. This explains why I am on youtube watching tutorials on it as well as why I had to look up the concept of "Typescript.".
All that I was trying to express though in my prev comment is that the questions prompted in this mock interview are just a tool for the person conducting the interveiw to assess your ability to problem solve. It makes sense to me that the questions in the end of the interview would seem almost irrevelant and entirely unorthodox to the convention of standard coding so to ensure that they aren't rotely memorized. Were the interviewee to get these correct, surely it'll exceed the expectations of the interveiw and thus ensure that he or she is a spectacular candidate.
Cheers!
Thanks ) Love your videos!
cont x=[1,2,3];
x.indexOf[10000] will be -1 as you said but when I tried doing that it's getting undefined.
If you watch the video there is another line which is missing here. if you add that you will get expected result.
X.indexOf(10000). Wrong brackets
=== compares value and data type right (value same)(type of nan is number so data type also same)value same data type same it will returns true right
Nan is an exception, you will get false
Thank you
Great 👍
Love your videos man.
Hello sir,
The last question (NaN ===NaN) will give false
Thank you so much ❤❤❤
But Where is the link of the negative index video?!
Here it is: ruclips.net/video/pFEdFfB2ewE/видео.html
Thank you, Man!
write code to display even number s from 20 to zero using the Do-While loop Javascript
This is my code its not correct, I need some help please
var i = 0;
var n = Number(window.prompt("Enter any number : "));
do{
i--;
document.write("Number is = " + i + "");
}while(i
Thanks
Welcome
Thank you so much sir
Thanks for watching venkatesh.
sir ascending & descending order code is not working it gives same array
Please you said in minute 03:00 that you will provide a link of negative index video in Javascript so where is the link of the negative index in Javascript video?!
I couldnt find the tutorial on negative indexes. Could someone please point me to it?
Here it is: ruclips.net/video/pFEdFfB2ewE/видео.html
whats the reason ary.sort() treated the array as a string?
Liked before watching crew
Thanks for the like:)
ary.sort((a,b)=>aa-b)
For numbers you need to use a-b
Hello sir
In interview i was get ask for the below question and expected result part of array convert string .
Question
var sampleArry = [1,2,3 {a:4, 5} 6, 7 , 8, [9,10] ]
Expected [1,2,3,4,5,6,7,8,9,10]
Can you please explain how to fix it. In question of array there is tricky part of object in side of array which is not canvter as a string.
Kindly reply
What abou this ?
var sampleArry = [1, 2, 3, { a: 4, b: 5 }, 6, 7, 8, [9, 10]];
sampleArry[7].map(res => {
sampleArry.push(res);
});
sampleArry.splice(7, 1);
let obj = Object.values(sampleArry[3]);
sampleArry.splice(3, 1);
sampleArry.push(...obj);
console.log(sampleArry.sort((a, b) => a - b));
const arr = [[0, 1], 33, {a:4}, [2, 3], [4, 5]];
const newArr = arr.reduce((acc, b) => {
if(Object.values(b).length) b = Object.values(b);
return acc.concat(b);;
}, []);
console.log(newArr);
very nice...
where is the link of minus index tutorial sir?
I was going to upload that video with this video but go busy. I will upload this weekend.
why maxvalue - maxvalue gives maxvalue, and not zero
great video sir
NaN === NaN; // false
because NaN, and only NaN, will compare unequal to itself.
You are the best!
Last statement is results by false thus one NaN not equal to another NaN
In the video 12.17, if b is a global variable. Why it didn't print at first time. Please reply back
Because program stopped running after it gets an error from console.log(a)
@@kannu755 Thank you ...
05:25
I don't seem to get it to work by using return a > b.
Weird thing is that if I return a - b then it works properly. Am I doing something wrong?
Thank you in advance.
const arr = [1, 2, 15, 30, 5, 45, 7];
console.log(arr.sort((a, b) => {
return a - b;
}));
That is a correct syntax for the callback. a-b is correct.
@@Techsithtube
I made a fiddle in which I console log the example you used in this video that isn't working for me.
jsfiddle.net/2yr69pn7/
I'm really confused why the minus sign is doing the sort correctly but the less/greater than sign isn't.
Thank you for the instant reply! That caught me off guard haha :D
Its basically how the sort is implemented in javaScript other languages a>b makes sense but javaScript decided to go this way.
video is great but HR would not ask so many tricky and meaningless question for one student. Such question based on concepts but far away from the real world
Hi, for me it's showing 5e-324 when I do Number.MIN_VAL / 1
There was i / i not i / 1.
I am really early I deserve love... Jokes aside, great content as usual!
Thanks for the first comment:)
11:05 - the weirdest part is if you console.log 17 fives it will return 55555555555555550.
Shouldn't it have "..60" on the right?
And console.log(44444444444444444); gives us this: 44444444444444450.
Doesn't make any sense =)
As i said in the video after 16 numbers its all wierdness so you should not have integers that are longer than that.
techsith, I am still having doubt. Why it wasn't like 55555555555555560 with 5's similar to 44444444444444450 with 4's. I know, after 16 digits, it's all absurd but with others, we see that 16th digit increments and further digits truncates to 0s. Please clear me also on this. Anyways, I liked this video a lot. Keep going!
Super
Nice!
The one you mentioned for sorting is not working
which particular one?
hey! why are checking comments
As a primarily c++ programmer, I am thoroughly confused :)
JS is confusing for programmes from other languages. First of all its nonblocking and second of all it has lots of weird things that you can still use it but you shouldn't. I would suggest to learn only latest JavaScript .
Javascript is awesome!
indeed :)
This is an Interview question. Can anyone explain the answer why when using for loop inside "var" 10 times iterating and showing undefined and when using "let" for loop inside getting the 1,2,3,..., 10.
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (var i = 0; i < 10; i++) {
setTimeout(() => console.log(a[i]), 1000);
}
Note:-
0/0 is NaN
1/0 is Infinite
Hello Sir,
i try same but i get wrong result ...
const ary = [1,21,334,44,2,3,4,5,667,7,8,80,55];
alert(ary.sort());
alert(ary.sort((a,b) => {
return a < b;
}))
alert(ary.sort((a,b) => {
return a > b;
}))
what's wrong here...
what did you get?
Should be return a - b
I feel like I'm applying to be a Mathematician and not a Developer lol
Lol. Math is very important to pass as an engineer.
hmm, I think logic is more important but I can be wrong, good video btw. made a lots of people salty XD
8:55, but Infinity != 0
11:53 how did the '6' come in?
Because it truncates.
Output for last will be false,
Thanks,
Answer is last question is true
NAN === NAN returns false
Hi,
Could you tell me Y this result is coming in my console?
var i = Number.MIN_VALUE;
console.log(i);
console.log(i+i);
console.log(i-i);
console.log(i*i);
console.log(i/i);
VM173:2 5e-324
VM173:3 1e-323
VM173:4 0
VM173:5 0
VM173:6 1
THere is a MIN_VALUE in javaScript that is the smallest possible number. and adding one to it changes that number slightly. removing from the smallest number should make it a 0 same with multiplication. however, dividing the same number should give you one.
the last question should be printed false
Nan is also Nan so return false
IQ
I Q......