Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I came across this question:.
Sort an array using javascript.
My ans: .sort() method, the other person asked me to use the bubble sort algorithm and sort it.
Does that make any difference?
As a practical matter, you are much better off using the built-in sort, which is much more efficient than a bubble sort, implemented in a much faster language than Javascript, and programmed by someone better at it than you.
As an academic assignment, though, it's a good one. You should write your own bubble sort and use the built-in to compare it for accuracy and speed.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector() tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:
let qs = selector => document.querySelector(selector);
Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?
Thanks.
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
To me, it seems that whatever logic I would write in a for/while loop could be placed in the callback passed to map, reduce, filter. I'm sure you might have to modify the code some but in theory I can't image a situation where you're forced to use a for/while loop.
Can anyone provide examples where its required to use a for/while loop?
If the statement were false, no functional programming language could exist. In other words: all imperative solutions can be rewritten as declarative ones. However, there might be implementation details that can be imperative (hah) to your particular use case. For example, breaking nested loops based on complex conditions is something that is typically easier to implement in an imperative form.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm fairly new to Javascript, and filled with questions, most of which I'm able to find the the answers to online. However, there is the rare occurrence when my wording of a question doesn't correctly communicate the idea I'm trying to portray. That's when I come to Stack Overflow, and try to communicate more visually.
Which of these two examples is more commonly acceptable when programming with Javascript?
Method 1:
var one = 1;
var two = 2;
Method 2:
var one=1,
two=2;
Are there more specific (organizational) occasions when Method 2 should be used?
Example:
// Food
var pizza,
sushi,
cheeseburger;
// Utensils
var fork,
spoon,
excalibur;
Just in-case you believe the answer to this question is purely subjective, I pose a different question for you: which way (in terms of storage) is more efficient, and is the size of the difference insignificant for larger-scale web apps?
The virtual machine treats the two identically. There will be no performance difference between the two. Stylistically some developers prefer the former, while I have always used the latter. Ultimately whatever you find more readable and whatever is the communalized standard at your organization is the one to go with.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
As I am learning vanilla JavaScript right now, I don't always know what to ask when searching through JS documentation (mostly on Mozilla MDN). So, I use what I know in jQuery until I get there.
So, what performance or other drawbacks should I be aware of when using jQ to substitute for my lack of full JS understanding while I learn?
These days, clients run fast enough that you don't really need to worry about any performance differences between vanilla JavaScript and jQuery. Thus, it could be said that this is a sort of "premature optimization", so I give you the same answer I always give: Use what you know/what's easier to maintain until you can demonstrate a critical performance bottleneck via a profiler; only then should you figure out how to improve the performance, possibly including switching to vanilla JS.
You should learn to understand how to retrieve elements from the DOM and how javascript relates to HTML. Basically you are altering html-elements and attributes.
http://en.wikipedia.org/wiki/Document_Object_Model
http://www.w3schools.com/js/js_htmldom.asp
https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
One of the interviewers asked to impress him with the JavaScript and CSS skills. He provided a link to two websites and asked to write a JavaScript application (page or pages) that takes content from one or both of these websites and demonstrates my command of jQuery and CSS. It doesn’t have to be useful to end-users, but it should be interesting to programmers.
What interesting things should I write? What would impress you in the candidate?
P.S.
The sites have real-estate information.
So, what would be the best way to read information from a given URL and extract some of it using jQuery?
That interview question is so subjective. What impresses one person might be basic to another. Why not ask a more meaningful question that demonstrates whether or not the candidate actually knows the language.
With all that said and if you really want to work for this company, I would study up on the basics of both js and jquery and really learn how to optimize basic functions. If you had to impress me then you should try to optimize a block of code as best you can without making the code unreadable. There's nothing better than clean, fast and readable code.