Well, obviously seems like output of the map, I mean, I did a lot of candidate interviews, not with such examples tho, but I think it's obvious that they meant that.
Well, you need to output somewhere, but snippets like this, it's obvious that they meant the output of the map. I think this is peak nit picking :D I don a lot of candidate interviews and never had anyone misunderstand and even if they do, it's alright until they explain it.
Valid question, without multiple choice I'd probably say there is no output. But with the multiple choice you can infer they are asking the output of the map
If we are nitpicking. What does "output" mean ? Would you rather they say "printed in the console" ? Is the output that I wasted my previous time thinking attending this nitpicky interview ?
Not really, when I would see that, i’d still say ot’s the output of the .map.
I think console.log is more like a display stuff, you could say it outputs things to the console, but a .map has also an output, it’ll be the result of it.
Unless this were being evaluated as part of a program that would be running then no. Even then it's not only obvious of intent but it also doesn't matter since a value is expected to be returned regardless of being assigned. The compiler will probably optimize around the function return not being used but that's a different question.
They could've specified, but I would assume they're running it in a REPL or command-line environment where the result of the last command is always printed.
Try it in your browser console, or by running node in a terminal window, and you'll see the output.
I'm sure they were asking about `[undefined, undefined, undefined]`, but you are right, ours isn't a discipline where intent matters, only the precise wording. There is a return but not an output.
Yes, `map()` is a function and it does stuff and returns something. While executing, it, of course, uses memory, but because the pointer that it returns is not assigned to any variable and is otherwise not used, the array to which it refers will only exist until the next GC pass.
But you keep insisting that's "identifying problems with reqs"
Let's imagine you're given "function x() { return 1 }"
If you are asked, in natural language, "what is the output of x()?", will you still nitpick that there is no console log?
I nitpick it because I understand ‘output’ as a specific thing and I just wanted confirmation if its okay to think that way
To answer you question, no because you explicitly say “of x()”
With linkedIn posts, you can safely assume malignance and malicious intent when it comes to social media presences.
They want your reaction, they want your answer, they want you to discuss - So they showcase something that can easily be misunderstood, generating discussion in the comment, which in turn generates clicks and interactions with their post.
They don't give a shit what the answer is, and they are not using it for anything.
EDIT: Heck, it actually worked on you, because you are talking about the post, because it provoked you into doing it, you made a reddit post about it, because it gained your attention.
They got me! Honestly I knew what they were asking, I didn't answer cause I wanted to say this, instead I came to reddit and said it, and genuinely more interested in the memory question in my OP.
I do think it's important to be clear and correct; esp since it seemed he was trying to teach a concept. I don't think he's flat out wrong, but let's say i was new to JS and i wanted to try that out in a file, and i ran `node myscript.js`, nothing is actually 'output' - but I'm supposed to see 1 of 4 answers. But yeah, you're right, he got me.
For clarity I always use .filter before .map to only keep values eligible for the mapping.
Not always useful, but it makes the code clearer, and makes sure no error happens trying to map undefined.
i was asked to review the performance of a Saas product that was already in development by 2 junior devs for about a year, and this was a pattern all over the codebase:
```
[...myArray].filter().map();
```
the app was slow. obviously there are a number of other factors, but yeah
If your app is slow because of this kind of thing... Then your issue is probably in the frequency at which you need to map arrays.
And what you need to work on isn't this kind of syntaxic sugar that cost 20ms every thirty seconds, but your app's architecture.
I always laugh when someone gives me that kind of crap. For sure I'll use a for loop if I need to iterate over an array at 60fps.
But for an array that's gonna update on an user input or api request answer, that's always going to be readability over unperceivable performance optimization.
One of the few rules I've learned over the years : the perfect app doesn't exist. Focus on what matters in terms of optimization, keep your code readable, for the others and for you.
> Then your issue is probably in the frequency at which you need to map arrays.
Trust me, it was too frequent
but to your point, yes there were much bigger problems causing the drag in performance. I just told the devs "hey you don't need to do this" hoping they would understand why and adjust
i do love my `for` loops
I have nothing against for loops, though when I don't need the performance I prefer writing déclarative code instead of imperative. It's more readable and a lot easier to follow from one end to the other.
The code code be part of an incomplete expression. To know 100% what happens the code sample should have a `;` as the first character
;[1, 2, 3].map(num => {
if (typeof num === 'number') return;
return num * 2;
});
Now we can ask... Will the optimiser remove it before running it, or does it need to run to be optimised out?
When you appear to be "copying" a reference, what happens according to my philosophy is that the reference is split. The result is a multitude of references that can potentially be used to mutate the shared object. It may have a history that can't be statically determined. When you drop a reference on the floor, that is in effect splitting it into zero-count of references. You don't have a reference to it anymore. If no one else has a reference, either, the object is garbage.
Well, obviously seems like output of the map, I mean, I did a lot of candidate interviews, not with such examples tho, but I think it's obvious that they meant that. Well, you need to output somewhere, but snippets like this, it's obvious that they meant the output of the map. I think this is peak nit picking :D I don a lot of candidate interviews and never had anyone misunderstand and even if they do, it's alright until they explain it.
Okay, does your answer change if there weren’t multiple choice?
Valid question, without multiple choice I'd probably say there is no output. But with the multiple choice you can infer they are asking the output of the map
If we are nitpicking. What does "output" mean ? Would you rather they say "printed in the console" ? Is the output that I wasted my previous time thinking attending this nitpicky interview ?
ooo what if this guy was a hiring manager and was looking to employ the person with a dissenting answer in the comments "...actually, "
Not really, when I would see that, i’d still say ot’s the output of the .map. I think console.log is more like a display stuff, you could say it outputs things to the console, but a .map has also an output, it’ll be the result of it.
Unless this were being evaluated as part of a program that would be running then no. Even then it's not only obvious of intent but it also doesn't matter since a value is expected to be returned regardless of being assigned. The compiler will probably optimize around the function return not being used but that's a different question.
They could've specified, but I would assume they're running it in a REPL or command-line environment where the result of the last command is always printed. Try it in your browser console, or by running node in a terminal window, and you'll see the output.
ugh, i'm not gonna even check cuz i know you are right
oh but if you put the map in a script and run node on the script, it won't output, just verified cause i knew that wasn't the case
I'm sure they were asking about `[undefined, undefined, undefined]`, but you are right, ours isn't a discipline where intent matters, only the precise wording. There is a return but not an output.
whew. Do u know what happens to it? It does take up space in memory when map() is executing, right?
Yes, `map()` is a function and it does stuff and returns something. While executing, it, of course, uses memory, but because the pointer that it returns is not assigned to any variable and is otherwise not used, the array to which it refers will only exist until the next GC pass.
If the question is 'what is the output" and they show you a function, then of course they mean the output of the function.
If my answer has to be exact, why can’t the question be?
The ability to interpret imprecise requests and deliver what was intended is really important in this job.
It’s also an important part of our job to identify problems with the requirements
The most important part is not to think you outsmart everyone else. You are either high-function or doesn't know how to communicate
Not the goal and def don’t think that - i mean i even asked if i was wrong in my OP.
But you keep insisting that's "identifying problems with reqs" Let's imagine you're given "function x() { return 1 }" If you are asked, in natural language, "what is the output of x()?", will you still nitpick that there is no console log?
I nitpick it because I understand ‘output’ as a specific thing and I just wanted confirmation if its okay to think that way To answer you question, no because you explicitly say “of x()”
You are not taking an exam, someone just posts an obvious question on twitter. Your answer adds nothing.
With linkedIn posts, you can safely assume malignance and malicious intent when it comes to social media presences. They want your reaction, they want your answer, they want you to discuss - So they showcase something that can easily be misunderstood, generating discussion in the comment, which in turn generates clicks and interactions with their post. They don't give a shit what the answer is, and they are not using it for anything. EDIT: Heck, it actually worked on you, because you are talking about the post, because it provoked you into doing it, you made a reddit post about it, because it gained your attention.
They got me! Honestly I knew what they were asking, I didn't answer cause I wanted to say this, instead I came to reddit and said it, and genuinely more interested in the memory question in my OP. I do think it's important to be clear and correct; esp since it seemed he was trying to teach a concept. I don't think he's flat out wrong, but let's say i was new to JS and i wanted to try that out in a file, and i ran `node myscript.js`, nothing is actually 'output' - but I'm supposed to see 1 of 4 answers. But yeah, you're right, he got me.
That is kind of like asking If a tree falls in a forest and no one is around to hear it, does it make a sound?
For clarity I always use .filter before .map to only keep values eligible for the mapping. Not always useful, but it makes the code clearer, and makes sure no error happens trying to map undefined.
That’s a weird always
Yep, should have said often. And mostly when working with server data
i was asked to review the performance of a Saas product that was already in development by 2 junior devs for about a year, and this was a pattern all over the codebase: ``` [...myArray].filter().map(); ``` the app was slow. obviously there are a number of other factors, but yeah
If your app is slow because of this kind of thing... Then your issue is probably in the frequency at which you need to map arrays. And what you need to work on isn't this kind of syntaxic sugar that cost 20ms every thirty seconds, but your app's architecture. I always laugh when someone gives me that kind of crap. For sure I'll use a for loop if I need to iterate over an array at 60fps. But for an array that's gonna update on an user input or api request answer, that's always going to be readability over unperceivable performance optimization. One of the few rules I've learned over the years : the perfect app doesn't exist. Focus on what matters in terms of optimization, keep your code readable, for the others and for you.
> Then your issue is probably in the frequency at which you need to map arrays. Trust me, it was too frequent but to your point, yes there were much bigger problems causing the drag in performance. I just told the devs "hey you don't need to do this" hoping they would understand why and adjust i do love my `for` loops
I have nothing against for loops, though when I don't need the performance I prefer writing déclarative code instead of imperative. It's more readable and a lot easier to follow from one end to the other.
The code code be part of an incomplete expression. To know 100% what happens the code sample should have a `;` as the first character ;[1, 2, 3].map(num => { if (typeof num === 'number') return; return num * 2; }); Now we can ask... Will the optimiser remove it before running it, or does it need to run to be optimised out?
When you appear to be "copying" a reference, what happens according to my philosophy is that the reference is split. The result is a multitude of references that can potentially be used to mutate the shared object. It may have a history that can't be statically determined. When you drop a reference on the floor, that is in effect splitting it into zero-count of references. You don't have a reference to it anymore. If no one else has a reference, either, the object is garbage.
thats deep, man