array.max() / array.min()
Started by
infogulch
, Sep 05 2011 08:06 PM
24 replies to this topic
Contains++
#16
-
Posted 04 January 2012 - 10:15 PM
Contains++
Good question, what happens when you increment a function?
obj := { fn: Func("function") } obj.fn++ msgbox % obj.fn() function() { return A_ThisFunc " called!" }
Hmm doesn't do much, just calls the function...
:lol:
#17
-
Posted 04 January 2012 - 10:21 PM
great obfuscation technique too
#18
-
Posted 04 January 2012 - 11:49 PM
That's a bug. The correct behaviour is to assign and return an empty string. Instead, it skips the assignment and returns an empty string. obj.fn := obj.fn + 1 and obj.fn += 1 should produce the correct result.Hmm doesn't do much, just calls the function...
#19
-
Posted 05 January 2012 - 09:09 AM
Oh, uh well I totally meant to point out that bug...
In any case, what do you guys think of Max() and Min() ?
I've been thinking, I would actually prefer to have two additional built-in object functions: ObjMax() & ObjMin().
This would allow the greatest flexibility.
[*:16dxnusg]Use it on an existing object: myobject.max()
[*:16dxnusg]Create an object just to find the max value: ObjMax([1,12,123,1234])If some crazy person (me) wants something that returns the min/max of args, a simple variadic function wrapper would work great:
In any case, what do you guys think of Max() and Min() ?
I've been thinking, I would actually prefer to have two additional built-in object functions: ObjMax() & ObjMin().
This would allow the greatest flexibility.
[*:16dxnusg]Use it on an existing object: myobject.max()
[*:16dxnusg]Create an object just to find the max value: ObjMax([1,12,123,1234])If some crazy person (me) wants something that returns the min/max of args, a simple variadic function wrapper would work great:
max(x*) { return ObjMax(x) } min(x*) { return ObjMin(x) } max(a, 123, c * 4)
#20
-
Posted 05 January 2012 - 04:03 PM
I thought also about this. Even already implemented Methods seem to be inconsistent;
All in all, obj.contains(), obj.count() are very important, but actually just for lists and not required in the base Object.
Wouldnt it be a better idea, to provide a second Object called List/Collection, which provides that functionality? Is this possible with the current prototype implementation?
If this is not an option, we could at least provide a standard lib with classes for Collection, Delegate etc, which are shipped with AHK_L.
names := [] names.Insert("Mary") names.Remove("Mary") ; won't work, as remove bases on indexesThis goes in the same direction of "obj.IndexOf(value)"
All in all, obj.contains(), obj.count() are very important, but actually just for lists and not required in the base Object.
Wouldnt it be a better idea, to provide a second Object called List/Collection, which provides that functionality? Is this possible with the current prototype implementation?
obj := {} ; create a standard key-value Object (which is actually a dictionary) array := [] ; create Collection/List with .count(), .add(val), .remove(val), .sort() etc.
If this is not an option, we could at least provide a standard lib with classes for Collection, Delegate etc, which are shipped with AHK_L.
#21
-
Posted 07 January 2012 - 09:22 AM
Even already implemented Methods seem to be inconsistent;
; Compare names.Insert(1, "Mary") names.Remove(1) ; to names.Insert("Mary") ; Push names.Remove() ; Pop
#22
-
Posted 09 January 2012 - 05:51 AM
+1 for .keyCount()
(count of numeric and non-numeric keys combined).
#23
-
Posted 09 October 2013 - 01:08 PM
New Autohotkey forum: http://ahkscript.org.
Count() for both array and dictionary. Min/Max is not so useful compared to Count. cardinality is basic premise of any collection. Array can live with with MaxIndex(). I was surprised to find that dictionary doesn't have so basic count (), which diminished its usefulness.
#24
-
Posted 16 December 2013 - 01:41 AM
For reference purposes :
ObjCount(Obj) { if (!IsObject(Obj)) return 0 z:=0 for k in Obj z+=1 ;or z:=A_Index return z }
#25
-
Posted 30 April 2014 - 10:52 PM
Why ahkscript.org? - autohotkey.com is outdated