Lists and list lengths

Not sure how to reconcile this but it feels wrong, so maybe someone can help me out.

I’m creating some lists and setting some conditions so that only some of the list numbers get used. What’s interesting is that creating a new list subject to restrictive conditions of the first appears(according to Desmos) to have no effect on the list length. Almost as if the array is not affected by this… and yet it is, visually. Here’s what i mean, with a pic:

The sublists contain many undefined values and of course as expected do not plot anything. So far so great. I realize that javascript kind of handles this a bit differently than what we might hope for, but here I am hoping. Seems to me that undefined elements of an array really should affect the array.length property, at least mathematically, based on the graphing of said array seen here.

Any thoughts on this? Thanks!

Use brackets instead of curly braces.

That generates a syntax error unfortunately, but thank you.

Hi there, Mike. I’m not sure why square brackets are giving you an error, but that’s the syntax you want for filtering.

The condition behavior isn’t a consequence of JavaScript interaction. It’s just that conditions “broadcast” over lists in the calculator the same way that other operations do, and conditions either evaluate to 1 or NaN/undefined. So if you have a list of conditions with a mix of true and false results, you get a list with a mix of 1s an undefineds. Nothing about this changes the list length (though as you mentioned, points with undefined coordinates or curves with undefined parameters won’t plot).

If you want to filter a list, the way you do that is with our indexing syntax (square brackets). I’m not sure why that’s giving you an error, but it shouldn’t. Here’s a link to a graph with some exposition. And here’s another graph with a bunch of examples of fancy ways to work with lists, including methods/syntax that alter list length.

2 Likes

Odd. Here’s what I get with your graph:

1 Like

Thanks Chris!

By javascript i wasn’t referring to interaction behaviour but rather how js counts elements of an array(inc NaN, etc.) even though they’re not valid mathematical entities.

All makes sense, thanks very much!

Thanks Daniel!

By brackets I thought you were referring to () rather than []. Merci!