is javascript Math.sin() O(1)? [closed] - javascript

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 5 years ago.
Improve this question
I am wondering if Math.sin(), Math.cos() are O(1), and how is it translated to the compiler.
We can create a match table for it.
Or we can create a not so detailed match table and use a linear formula to calculate the value.
Or we can break it down.
I guess in any sense Math.sin() is sorta O(1) as the input is bounded, but how exactly is it done in the compiler and how complex it is?

It might be impossible to give a definite answer, so I will try to provide you with as much information as I can instead.
The Math object implementations can differ between browsers and operating systems ("Note that many math functions have a precision that's implementation-dependent. This means that different browsers can give a different result, and even the same JS engine on a different OS or architecture can give different results.[1]").
There are a few major ways in which a sine function can be implemented:
Taylor series approximation
CORDIC algorithm
Complexity will depend on implementation. As far as I know, CORDIC algorithm is more common.

Related

What is a List ? [JavaScript interview question] [closed]

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 2 years ago.
Improve this question
What exactly is a "List" in JavaScript?
I got asked this question and I'm a professional of five years but this made me fumble.
I understand Arrays, Stacks, Queues, even Linked Lists.
But isn't a List just an Array in JavaScript? Because then I got asked what the difference between a List and an Array was, and I said no difference - and never got to know if that was right.
I understand the differences between the data structures List and Array in C# and Python but I don't get this one for JavaScript.
I understand the downvotes ... it was indeed a dumb question, I think I should have known that Lists weren't a type in JavaScript and tackle the dumb question that way.
For anyone this may prove useful: For front-end engineer interviews, make sure you know that JavaScript is a dynamic language, meaning the data structures are very different from static typed languages like C and Java, and even have different meanings in Python even though Python is a dynamically typed language similar to JavaScript.

What is the maximum number of tags should contain a page that does not significantly slowed down? [closed]

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 6 years ago.
Improve this question
I need to create a project of web application that contains a very long list of items and I can't use pagination...
How many tags is optimal for the single website from the point of view of the optimization?
When the website begins to slow down due to the large number of tags?
How do you deal in a different way than the pagination?
Can you suggest a javascript library free for commercial use?
As mentioned by #gus27 it all depends on what operating system, browser and most importantly the resources such as CPU and memory that is available to the browser for use.
Having said that, modern browsers can easily handle 100s if not 1000s of tags. The best way to go about optimization is to go make the system and when you hit a bottleneck try to find out the reason for it and then fix it. Don't worry about efficiency until you hit a problem which requires optimization.
Angular.js is the javascript that comes straight to my mind for the kind of javascript library that i think you want.

Javascript Syntax: Variable Declarations [closed]

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.

Javascript sorting vs .sort() [closed]

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.

What are some techniques to facilitate safe refactoring in Javascript? [closed]

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 8 years ago.
Improve this question
I'm coming from statically typed languages like C++ where there are tools (the compiler for one) that will remind me if I forget something obvious while refactoring. For example, if I change the number of arguments to a function but I forget to change all the calls to it. But it seems really easy to make this type of mistake in javascript. How do you avoid problems like this when refactoring javascript?
just like you do in c++/java. By writing tests.
Unit tests are the best. If you code is MVC, then you can certainly have unit tests with little effort, at least for the model layer. The benefit is you get feedback immediately. Check out QUnit
Functional tests via Selenium or equivalent are good too. They will find problems, but not immediately.
Only thing like that I can think of is: JSLint (http://jslint.com/)

Categories