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
For the functions f(x) = 2x − 6 and g(x) = 5x + 1, which composition produces the greatest output? A. Both compositions produce
o-na [289]
F(g(x)) = 2(5x+1)-6 = 10x+2-6 = 10x-4

g(f(x)) = 5(2x-6)+1 = 10x-30+1 = 10-29

10x-4>10-29 because from f(g(x)) you subtract less quantity. 
The answer to your question is C. I hope that this is the answer that you were looking for and it has helped you.
8 0
4 years ago
Find the range of possible values for y.
nikdorinn [45]
I hope your not that lost now.

Finding the range of a function y=f(x) is the same as finding all values that y could be. To do this, we can think of it this way: The range of f(x) is all the y-values where there is a number x with y=f(x).
5 0
3 years ago
on his way to visit his sister at college,gregg drives 135 miles in 3 hours.what is his average rate or speed in miles per hour
elena55 [62]

Answer:

45 m/p

Step-by-step explanation:


7 0
3 years ago
Read 2 more answers
Find the slope of the line that passes through (4,-5) and (-2,9)
stiks02 [169]

Answer:

C) -7/3

Step-by-step explanation:

m=(y2-y1)/(x2-x1)

m=(9-(-5))/(-2-4)=(9+5)/-6=14/-6

simplify -14/6 to -7/3

4 0
3 years ago
HELP ME PLEASE!! 10 POINTS!!
WITCHER [35]

Answer: 1.65

I hope this isn't too late : )

3 0
3 years ago
Other questions:
  • 10m3 of air weigh 13 kg. Chapter Reference c How much does the air weigh in a room 4.2m long, 3.5m wide, and 2.6m high?
    11·1 answer
  • Solve for X on both sides<br><br><br> 9x+4≤58 or 1\6x−2&gt;3
    12·1 answer
  • Please help to answer this question I’m really confused
    11·1 answer
  • Find the volume<br> If the rectangular prism of this 3m,11m,3m and what is the answer
    13·1 answer
  • 2 less than one-third of the points that the Panthers scored
    5·2 answers
  • Find the additive inverse of 3x−6
    11·2 answers
  • Find the x- and y-intercept of each function.<br> 1) x + 2 y = -6
    8·2 answers
  • Write each quadratic expression in standard form. Draw a diagram if needed.<br> (x+4)(x-1)
    6·1 answer
  • NEED HELP FAST PLZ!!
    14·1 answer
  • Lines a, b, c, and d Intersect as shown.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!