1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ioda
3 years ago
14

Help

Mathematics
1 answer:
Ann [662]3 years ago
7 0

Step-by-step explanation:

ES6 has a new Set data structure for storing sets of unique objects. However it is based on object references as opposed to value comparisons. As far as I can tell this makes it impossible to have a set of pairs of numbers without stringifying.

For example, typing in Chrome's console (needs Chrome 38+):

> var s = new Set(); < undefined > s.add([2, 3]); < Set {[2, 3]} > s.has([2, 3]) < false <--- was hoping for 'true'

This appears to be by design: since I passed a different array of [2, 3] to has(), it returns false, because although the contents is the same it only looks at object references, and I allocated a new and different array to pass to has(). I would need to store a reference to the original array I passed to add() to check with has(), but this is not always possible. For example if the number pairs represent co-ordinates, I might need to check if the set has [obj.x, obj.y], but this will always return false since it allocates a new array.

The workaround is to stringify the arrays and key on strings like "2, 3" instead. However in something performance-sensitive like a game engine, it is unfortunate if every set access needs to make a string allocation and convert and concatenate number strings.

Does ES6 provide any feature to solve this problem without stringifying, or is there any feature on the horizon with ES7 that could help as well?

javascriptperformancedata-structuressetecmascript-6

Share

2

Follow

asked Sep 21 '14 at 13:06



AshleysBrain

20.4k1515 gold badges8181 silver badges119119 bronze badges

Add a comment

3 Answers

ActiveOldestVotes

3

As you've noted [2, 3] === [2, 3] is false, meaning you can't use Set like this; however, is Set really the best option for you?

You may find that using a two-level data structure like this will be better for you

var o = {}; function add(o, x, y) { if (!o[x]) o[x] = {}; o[x][y] = true; } function has(o, x, y) { return !!(o[x] && o[x][y]); } function del(o, x, y) { if (!o[x]) return; delete o[x][y]; // maybe delete `o[x]` if keys.length === 0

You might be interested in
A right triangle has one 64degree angle and one 90 degree angle
melamori03 [73]

Answer:

I dont know what your asking, for the other angle? Ig so. Answer: THE OTHER ANGLE IS 26. :)

Step-by-step explanation:

64 + 90 = 154.

All triangles add up to 180 degrees.

180-154 = 26.

7 0
4 years ago
Quadrilateral A and B are scaled copies of each other. Quadrilateral A has side lengths of 2, 3, 5, and 6. Quadrilateral B's lon
harkovskaia [24]

Answer:

Quadrilateral A has side lengths 2, 3, 5, and 6. Quadrilateral B has side lengths 4, 5, 8, and 10. Could one of the quadrilaterals be a scaled copy of the other ...

4 0
3 years ago
The ratio of dogs to cats is 2 to 3. There are 15 pets total. How many dogs are there? How many cats are there?
ElenaW [278]
So there are 2 dogs to every 3 cats (put into words)

in order to reach 15 total multiply both 2 and 3 by 3

2x3 = 6
3x3 = 9

so there are 6 dogs and 9 cats
6 0
3 years ago
A juggler tosses a bowling pin in the air with an initial velocity of 18 ft per second. It leaves his hand when it is five feet
Natali5045456 [20]

Complete Question

A juggler tosses a bowling pin in the air with an initial velocity of 18 ft per second. It leaves his hand when it is five feet from the ground and he catches it when it is four feet from the ground,How long is the ball in the air?

Answer:

t\approx 0.1s

Step-by-step explanation:

From the question we are told that

Initial velocity  V_0= 18 ft/s

Initial Height    h_1=5feet

Final Height     h_2=4feet

Generally the Newtons equation for motion is mathematically given by

   V^2 = U^2 + 2as

Where

    s=h_2-h_1\\s=4-5\\s=-1ft

And

   a=g=>9.81\\a=32.2ft/s^2

Therefore

   V^2 = (18)^2 + 2(-32.2)(-1)

   V^2 = 388.4

   V =19.70786645\\V=19.71ft/s

Generally the equation for Time is mathematically Given as

   t=\frac{V-U}{a}

   t=\frac{19.71-18}{32.2}

   t=0.05310559006

   t\approx 0.1s

Therefore the time spent on air by the ball is

    t=0.05310559006s

4 0
3 years ago
A triangle has sides that measure 3 cm, 4 cm, and 5 cm. What type of triangle is it?
NARA [144]
Scalene, because they all have different lengths on each side.
6 0
3 years ago
Other questions:
  • What is the solution to the linear equation?
    13·1 answer
  • Connie and two of her friends completed a 10-mile bike relay. each friend road an equal part of the race. what distance did each
    14·2 answers
  • Determine the 60th term of the sequence 10,25,40
    7·1 answer
  • PLEASE HELP 50 COINS!!!!
    8·1 answer
  • How can you use that ordered pair to find the unit rate, or constant of proportionality?
    14·1 answer
  • For the function f defined b f(x)=x^2+2x+3 find f(-x), -f(x), and -f(-x).
    5·1 answer
  • A boxplot helps to visualize the variability of a distribution. Five statistics form a boxplot, often referred to as the five-nu
    12·1 answer
  • MMMMMMMMMMMMMMMMMMMMMMMMM
    9·1 answer
  • Find the missing value using the given information<br><br> (4,p), (p,-3), m=5/3<br><br> Please help!
    13·1 answer
  • The terminal side of an angle in standard position passes through p(–3, –4). what is the value of tangent theta?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!