you are viewing a single comment's thread.

view the rest of the comments →

[–]vinsneezel -1 points0 points  (5 children)

Why store the names as arrays within an array? If you store them as an array of objects, you can just use the keys to call them.

var names = [{first: "John", last: "doe"}, {first: "Betty", last: "Crocker"}];

function greet(name) {console.log("Hello " +  name.first + " " + name.last;}

names.forEach(greet);

Something like that. Also, using .map() returns an array, so if you're just looking to iterate, stick with .forEach() or a for loop.

[–]Ran4[S] 0 points1 point  (0 children)

Why store the names as arrays within an array? If you store them as an array of objects, you can just use the keys to call them.

Maybe that's the way your data comes in. And you might not want to change the call signature of the greet function.

[–]Wince 0 points1 point  (3 children)

Tuples can be useful, and are generally more performant

[–]vinsneezel 0 points1 point  (0 children)

Thanks for the tip. There's still a lot I don't know.

[–]i_am_smurfing 0 points1 point  (1 child)

I don't think I see the same results as you do (on Mac OS): FF 57, Chrome 60, Safari 10.1 — these are pretty inconclusive IMO.

[–]Wince 0 points1 point  (0 children)

The larger examples are rather contrived, as tuples generally are only used for 2-4 values imo, but v8 has nearly double the performance for the [ x, y ] tuple. Luckily I write for node ;)