Annoymouse, Promises is.

Macrowski: Madsy, yeah, that’s better than mutating the array

Kimple: Well, how big is the array

Kimple: If you’re talking a multiple megabyte array you probably dont want to make a new one

Kimple: And would like to reuse the memory

Kimple: Also context is important. i’d say for most programs most of the time that filter is the right choice.

Bautiste: Does anyone know how to select an id of a div that is currenlty being shown then running a function based on the div being displayed

Budish: There’s something to be said for efficiency for larger arrays, yep. And there is something to be said for not having old “undefined” elements around.

Macrowski: Not sure what you are using that is leaving undefineds around.

Kimple: I’d avoid splice, since using that to filter in place will be On2

Marcone: Macrowski & tcsc : Thanks for the help. It’s not like there is some magic better way in other languages either. Unless you use linked lists or some other structure which isn’t random access

Kimple: You can do an in place filter in On. i’d recommend against it unless you have high performance requirements huge arrays or a 60fps limit

Kimple: You can remove in O1 from arrays

Hargenrader: Splice is the most powerful array method since you can add and remove indexes anywhere in the array, but readjusting indexes for all following indexes is very slow

Kimple: ArridxToRemove = arrarr.length-1; arr.pop

Demott: Use splice only when you need that extra power and be very cautious when using it in loops

Macrowski: Tcsc, but that wouldn’t maintain the order

Kimple: But how often do you care?

Kimple: Maybe 25% of the time?

Neglia: Tcsc: O1 if you don’t count the time complexity of arr.pop :-

Kimple: You can also do arr.length = arr.length-1;

Macrowski: Tcsc, I’d say quite often

Kimple: Idk if i can remember the last time that i needed to maintain the order when it wasn’t a sorted list or something

Kimple: You can filter in place in On and maintain order though

Dacamara: Tcsc: But nice trick, I didn’t think of using pop

Vanhamme: My immediate need didn’t need to preserve order

Kimple: Http://

Kimple: It literally just does filter but you write to the earlier part of the array you’re in.

Boiles: Why are Promises useful?

Macrowski: Annoymouse, for handling async code

Iino: Macrowski: hey! Long time no see

Delerme: Macrowski: what’s wrong with callbacks?

Macrowski: Annoymouse, you can avoid callback hell more easily

Macrowski: Nothing wrong with callbacks, promises is just an abstraction, there are still callbacks, but not nested

Mantilia: But in all the contexts that I’ve seen them used they seem to do the same thing as callbacks

Tietjen: I used it recently to do two xmlhttprequests at the same time and have it call me back when both are done, it’s great for that

Macrowski: Annoymouse, right, they do pretty much the same thing, but the flow is more linear, instead of having to read nested callabacks

Sponseller: Alex: i guess that’s better than nesting them

Ashcroft: Macrowski: it seems like there are many implementations

Dykema: Is there any standard or popular one I should use

Macrowski: Annoymouse, there is a spec, so they should all behave the same

Macrowski: Annoymouse, they come built-in with ES6

Macrowski: They are in browsers, and io.js already

Adee: Macrowski: is it safe to ***ume ES6 support already?

Galuska: Http://

Macrowski: Annoymouse, Promises is just a library, so yes, just include polyfill