Hacker News new | ask | show | jobs
by Olical 4713 days ago
It fills the array backwards because that is the most efficient loop possible within JavaScript when the order does not matter.

I added a pack method to enforce some weak limiting on the size of the array. This will only allow you to set an amount of values equal to the initial values that were set.

I know you can do it with `slice` etc, but the point was to make something a little different to an array or object inspired by the things I have been learning about functional programming.

Please, by all means, treat it as a cute demonstration. That's fine. I personally could see myself using something like this in some situations as a base type to extend from for example. Maybe as a generic coordinate storage system as I have shown in the post.

It has many flaws and might not fit in with your opinions or views, but saying "don't use anything like this code" seems a bit heavy handed to me. I think it has a time and a place, no matter how minute that time or place may be.

1 comments

Adding an implicit coercion to number to a tuple type that contains multiple elements in a dynamically typed language is just a bad idea. Period.
Okay, that isn't integral though. This could easily be left out if desired. It's not coercing to a number either, it's simply concatenating. This would work with strings too or any other type that supports valueOf.

You have valid points though. I just didn't like to think of this as something that could never be used in the real world. Or at least contain little ideas that could be used in the real world. It has at least some relevance.