1

Why are functions like Math.cos() and Math.sin() not working on array? So if I have an array, do I have to loop through to compute the cosine of all numbers in the array? Is there a distinction between arrays and matrices? Can I define a 2-dimensional matrix and access the elements using subscripts like x[2,3] for 2nd row and 3rd column?

1 Answer 1

2
  1. Yes you have to iterate yourself. The Math trig functions work on individual values only.
  2. JavaScript really has only one-dimensional arrays, but values of a one-dimensional array can be arrays. That gives an effect like multi-dimensional arrays, but it's really not exactly the same thing. (For most programming purposes, it's close enough.)
  3. Multiple dimensions are accessed as myArray[1][2], not with a comma-separated list of indexes.
Sign up to request clarification or add additional context in comments.

1 Comment

@canon they accept multiple arguments, but they do not accept arrays (unless they're called via .apply() of course). The point is that they're not "vector" operations. Still, edited to stipulate "trig functions".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.