|
Mark_Wallace wrote: Plus, people actually use android apps.
"universal" apps are only used if there isn't an alternative.
Two very good points. Agreed.
|
|
|
|
|
And falls into a coma.
Six-months later he wakes up in a car.
The woman is driving, and barking.
"Why are you barking?," the man says.
"So your son can stay asleep," she says.
"Shouldn't you be singing a ... lullaby ?," he says.
"Wait 'till you see the mutt," she says.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
And what are you smoking?
Not that I want any. I would prefer to keep my sanity.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Brisingr Aerowing wrote: And what are you smoking? Bill no smoke, no drug, all crazy natural no chemical additives.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
...and falls into a coma.
Six months later, she wakes to find she's no longer pregnant. Frantic, she asks the doctor what happened to her baby.
"You had twins! A boy and a girl, they are both fine - your brother named them."
"Oh no - not my stupid brother! What did he call them?" She asked, fearing the worst.
"Denise for the girl...."
She is hugely relieved! "That's OK!" she exclaims. "I like Denise, that's a good name!"
"...and the boy is Denephew."
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
he is a shelfish man
___@sHubHa
|
|
|
|
|
|
Just trying to create a Dictionary-ish class in JavaScript.
Wanted to make it as much as the C# one as possible.
The C# one has a constructor with an IEqualityComparer .
I thought I knew how it worked (I've written a few), but apparently I didn't.
Not enough to implement it without spending about an hour or two figuring out how it works anyway.
Why DOES an IEqualityComparer have a GetHashCode AND an Equals function anyway? Hash collisions you say? FFFFFFFUUUUUUU...
Now to work around the fact that JavaScript is a messed up "language" and dictionaries can't be implemented because it doesn't have a proper hash function
It's good to have a hobby
P.S. Ever wanted to mess up your Dictionary? Write an EqualityComparer where Equals always returns false. You haven't really lived until you've tried it
|
|
|
|
|
"When you realize you don't know what you thought you knew" ... that is when you, very temporarily, most often without suspecting it, have wisdom.
If (may the gods spare me) I had to emulate a .NET Dictionary in EcmaScript, I would be tempted just to make sure the 'Add function failed if the candidate Key was a duplicate, but I like the fact you are going for the full-monty, hash, and all.
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
|
I'm probably missing something here, but why do you want to reinvent the wheel?
No, there are no dictionaries in javascript <spit>, it's untyped afterall. But if you call them by the normally accepted name, associative array, you'll notice it's already built in, even in such a backwards language as javascript <spit>.
More info here: JavaScript <spit>- Objects as associative arrays[^]
|
|
|
|
|
I know objects are implemented as associative arrays so JavaScript kind of has a Dictionary.
JavaScript also has an array that sort of acts like a list (but "add" is called "push", it's also a queue and a stack, it doesn't even have a decent "contains" function (it does in newer browsers, but it's called "includes", because that's what it's called everywhere else, right?), etc.).
So, just like everything else in JavaScript, arrays and associative arrays suck, that's why I'm making my own
|
|
|
|
|
Ok fair enough, I suspected I was missing out something.
But I would assume the builtin funtions are a bit better optimized than anything you can implement yourself, so I would probably just try to add the missing functionality to the builtin arrays rather than starting over from the beginning.
|
|
|
|
|
"Premature optimization is the root of all evil" - Donald Knuth
|
|
|
|
|
Donald Knuth didn't know about javascript <spit> then.
|
|
|
|
|
I'll be sure to test for performance then
|
|
|
|
|
Hi Jorgen,
I doubt Donald Knuth ... in his worst nightmare ... could have ever imagined an enterprise with the scope of the WWW that would converge on using a lingua franca of a screwed up scripting tool, named after a language it had nothing to do with, stretched like a yogic contortionist to fit containers it never belonged in, patched-up with all kinds of graphic/widget extension junk, super-glued together with a half-assed mark-up language, duct-taped to a half-assed meta-mark-up style language, with all the flaws of Visual Basic ...
becoming a standard because it was the only "neutral ground" the major power$-that-be who ate the web, and are now digesting it into cash, could, by default, mutually tolerate.
Do I need to say that I don't like JavaEcmaScript ?
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
|
Sander Rossel wrote: Why DOES an IEqualityComparer have a GetHashCode AND an Equals function anyway?
(Just in case you weren't just asking rhetorically...)
Imagine Webster's Dictionary on your desk and you want to look up the word "Elephant". The Hash function lets you turn immediately to the page "ECMAScript to Elephanting", and the Equals function finds the specific word on the page. (A good summary is here .)
|
|
|
|
|
Thanks for the answer, but I knew (already looked it up)
|
|
|
|
|
var dictionary = {};
Done.
|
|
|
|
|
dictionary["Hi"] = "Hi";
dictionary["Hi"] = "Bye";
var o = dictionary["Bye"];
dictionary.forEach();
dictionary.toArray(); It's really not the same
|
|
|
|
|
Key-value pairing is sufficient for dictionary. It has amortized O(1) store, O(1) search/retrieve. There are one-liners for loop and conversion to array:
Object.keys(o).forEach(...);
Object.keys(o).map(i => o[i]);
But if you want more specialized non-dynamic dictionary, you can create your own class. The point was that is not true, that JS lacks of hash function for every value (it is just internal). It is a messed up language for lack of proper handling of primitive types, operator overloading and so on, but lack of hash function is not one of the reasons.
|
|
|
|
|
Plamen Dragiyski wrote: not true, that JS lacks of hash function for every value (it is just internal) To a user (me), having it internal is the same as non-existing as I still can't use it
Plamen Dragiyski wrote: But if you want more specialized non-dynamic dictionary, you can create your own class Exactly
|
|
|
|
|
Sander Rossel wrote: I thought I knew how it worked (I've written a few), but apparently I didn't.
That happened too many times in my life as a programmer. So I stopped assuming I know, to just accept my ignorance.
It even makes me happier so I know I will always have something new to learn.
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|