i was under the impression that `multiply()` had to be added on the prototype of `tuple()`'s result only..... function multiply(position) { let res = this[0][position-1] for(let i=1; i
Nice explanation. I did it by using transversing the tuple array. I have one question though. Why you added multiple in Array prototype ? Shouldn't it be tuple's property?
Depends upon the interviewer what they want to test. Both works. I added on tuple because of convenience as we dont need to take care of a lot of edge cases in thatcase.
Hi Yomesh, is there any video of yours for guiding for prep for interview like from JS Topics to cover + What concepts/kind of questions one must prepare as there are so many of them. Some folks keep posting huge list of JS concepts + Output based questions + Polyfill based questions + Any component implementation like Chip or OTP form etc. What to prepare form all of them ? Or maybe how much, it feels way too much.
Great explanation. Wondering if it'd be better to throw OR return something like NaN instead of 0 inside the multiple method when the array length is 0. 0 might be a valid return value as well and doesn't distinguish enough from an edge case (like the empty array)
Valid point. This is also a discussion point with interview about what is the expected behaviour. I agree that 0 is a valid output. However, we need to make a decision that should we break the application by throwing an error or return 0 that shows like a default output as for user if the application breaks then that is a really bad experience.
i was under the impression that multiply had to be added to the prototype of the returned array only and not on the entire Array.prototype function tuple(input) { const outputArr = [] let stack = [] for(const ch of input) { if(ch === '(' || ch === ',' || ch === ' ') continue else if(ch === ')') { outputArr.push(stack) stack = [] } else { stack.push(+ch) } } //ADD multiply to the prototype of the returned array outputArr.multiply = multiply return outputArr }
Can you please make a video on how to write regex expressions Also any explanation on why did you use prototype to find whether that index is present? It will be helpful
i was under the impression that `multiply()` had to be added on the prototype of `tuple()`'s result only.....
function multiply(position) {
let res = this[0][position-1]
for(let i=1; i
great explanation, keep up the consistency !
Thanks! ♥️
Nice explanation. I did it by using transversing the tuple array. I have one question though. Why you added multiple in Array prototype ? Shouldn't it be tuple's property?
Depends upon the interviewer what they want to test. Both works. I added on tuple because of convenience as we dont need to take care of a lot of edge cases in thatcase.
Hi Yomesh,
is there any video of yours for guiding for prep for interview like from JS Topics to cover + What concepts/kind of questions one must prepare as there are so many of them.
Some folks keep posting huge list of JS concepts + Output based questions + Polyfill based questions + Any component implementation like Chip or OTP form etc.
What to prepare form all of them ? Or maybe how much, it feels way too much.
Hey, I don't have curated list. This is too big so any list will become big eventually. I will try to create something already it ajd share soon!
Great explanation.
Wondering if it'd be better to throw OR return something like NaN instead of 0 inside the multiple method when the array length is 0.
0 might be a valid return value as well and doesn't distinguish enough from an edge case (like the empty array)
Valid point. This is also a discussion point with interview about what is the expected behaviour. I agree that 0 is a valid output. However, we need to make a decision that should we break the application by throwing an error or return 0 that shows like a default output as for user if the application breaks then that is a really bad experience.
Correct me if i am wrong.
line no 22:
can be replaced with current.hasOwnProperty(position) instead of borrowing has own property using call?
Yes, it can be used. However, it id advised not to. Check the following please
eslint.org/docs/latest/rules/no-prototype-builtins
i was under the impression that multiply had to be added to the prototype of the returned array only and not on the entire Array.prototype
function tuple(input) {
const outputArr = []
let stack = []
for(const ch of input) {
if(ch === '(' || ch === ',' || ch === ' ') continue
else if(ch === ')') {
outputArr.push(stack)
stack = []
} else {
stack.push(+ch)
}
}
//ADD multiply to the prototype of the returned array
outputArr.multiply = multiply
return outputArr
}
It works both ways. You can add it to tuple too. There are edge cases that you need to take if you add it to tuple.
Can you please make a video on how to write regex expressions
Also any explanation on why did you use prototype to find whether that index is present?
It will be helpful
Thanks for the suggestions! I will include it in future videos!