tag:blogger.com,1999:blog-2208890564265615027.post4058112155841466388..comments2024-03-08T19:47:41.485+11:00Comments on Ascii Dreams: Javascript.notEqual(highLevelLanguage)Andrew Doullhttp://www.blogger.com/profile/11099404183952971291noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-2208890564265615027.post-70655747653557021182011-10-02T17:46:07.517+11:002011-10-02T17:46:07.517+11:00Although I've seen Underscore mentioned a few ...Although I've seen Underscore mentioned a few times, I've not explored it deeply as I was planning on jumping straight to Coffee Script. But neither of two OSes I develop on can run npm (node package manager), so all that is on hold at the moment,Andrew Doullhttps://www.blogger.com/profile/11099404183952971291noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-58615576328331159942011-10-02T14:00:23.793+11:002011-10-02T14:00:23.793+11:00BTW, Underscore.js is a useful library to use with...BTW, Underscore.js is a useful library to use with Javascript; see http://documentcloud.github.com/underscore/ (and it has an isEqual function).Amithttps://www.blogger.com/profile/12159325271882018300noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-46613540072184194472011-10-02T13:57:56.856+11:002011-10-02T13:57:56.856+11:00Python and C++ have spoiled me. Javascript built-i...Python and C++ have spoiled me. Javascript built-in libraries are so primitive.Amithttps://www.blogger.com/profile/12159325271882018300noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-52550186304909310162011-09-30T14:23:07.759+10:002011-09-30T14:23:07.759+10:00Andrew: Yea, that's not documented anywhere :D...Andrew: Yea, that's not documented anywhere :D Here's how you do it:<br /><br />var a = [18, "stuff", {prop:3}];<br />a[a.length] = [1, 2];<br /><br />I'm not defending JavaScript or anything, it's got it's flaws like every other language. Just trying to share the knowledge :D<br /><br />Also, comparing two points:<br /><br />if(a.x == b.x && a.y == b.y)<br /><br />That's faster than a generic array comparison anyhow. Remember kids, JavaScript arrays are hashes too.<br /><br />var a = [1, 2];<br />a.stuffs = 3;<br /><br />Now a = {<br /> 0: 1,<br /> 1: 2,<br /> stuffs: 3<br />}QBRADQhttps://www.blogger.com/profile/13679791681970850232noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-76081571971046366892011-09-29T22:50:35.465+10:002011-09-29T22:50:35.465+10:00Trap for young players: If you're going to dec...Trap for young players: If you're going to declare an Array.prototype.compare you need to do so before you create any arrays... pushing works perfectly.Andrew Doullhttps://www.blogger.com/profile/11099404183952971291noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-6811394469077303922011-09-29T22:01:15.650+10:002011-09-29T22:01:15.650+10:00I've copied and pasted an implementation from ...I've copied and pasted an implementation from somewhere on the web (http://www.hunlock.com/blogs/Mastering_Javascript_Arrays) but I don't see why everyone should have to do this.<br /><br />QBRADQ: How do you compare two points to see if they are identical? Or matrices, or anything else which makes sense to refer to using an array... and comparison of object properties is even worse a problem.<br /><br />Of course, I'm now having further adventures in arrays, wondering why array1.push(array2) isn't working where I want array2 appended as a subarray in the (newly created) final element of array1...Andrew Doullhttps://www.blogger.com/profile/11099404183952971291noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-76477917458030601622011-09-29T10:30:41.862+10:002011-09-29T10:30:41.862+10:00JavaScript is very much an implementation language...JavaScript is very much an implementation language, which means you can do something like this:<br /><br />Array.prototype.compare = function(r) { /*Some compare code*/ }<br /><br />var a = [1, 2, 3];<br />var b = [1, 2, 3];<br />if(a.compare(b)) { /*Some stuff*/ }<br /><br />I don't really think of a use case for array comparison though. Maybe I'm too old :DQBRADQhttps://www.blogger.com/profile/13679791681970850232noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-73223759510819248452011-09-29T09:37:49.055+10:002011-09-29T09:37:49.055+10:00Re not knowing whether Javascript is passing value...Re not knowing whether Javascript is passing values by reference or by value: Javascript, like most high level languages, does not support pointers. This is Very Good Thing. Forget about pointers.<br /><br />I have only very basic JS knowledge, but if it's like other high level languages like Lisp, Python etc, then you can assume that all complex data types are passed "by reference". This does not mean any visible pointers are involved, but rather, that passing a value shares that value rather than making a new copy. Values are garbage collected when no references to them remain. <br /><br />Generally if you need to make a new copy of a value, you call some sort of "copyValue" function, which will return a reference to that new copy.eeeickythumphttps://www.blogger.com/profile/06423666849956415293noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-11123820612830276042011-09-29T08:54:31.697+10:002011-09-29T08:54:31.697+10:00How about JSON.stringify()? It should work for arb...How about JSON.stringify()? It should work for arbitrary arrays or objects.Ryanhttps://www.blogger.com/profile/17574626231451600275noreply@blogger.comtag:blogger.com,1999:blog-2208890564265615027.post-37511700918359181412011-09-29T08:45:38.112+10:002011-09-29T08:45:38.112+10:00You can try Array.join() to generate strings. But ...You can try Array.join() to generate strings. But that will only work on simple, unidimensional arrays.<br /><br />Other than that, yeah, everyone needs to implement their own comparing function.<br /><br />But yes, javascript is not high level. People are using languages that compile to it (see Coffeescript).kikitohttps://www.blogger.com/profile/18268036925187262614noreply@blogger.com