Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

array.max() / array.min()


  • Please log in to reply
24 replies to this topic
HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Contains++

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008

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...

:p :lol: :p

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
great obfuscation technique too

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Hmm doesn't do much, just calls the function...

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.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
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:
max(x*) {
    return ObjMax(x)
}
min(x*) {
    return ObjMin(x)
}

max(a, 123, c * 4)


IsNull
  • Moderators
  • 990 posts
  • Last active: May 15 2014 11:56 AM
  • Joined: 10 May 2007
I thought also about this. Even already implemented Methods seem to be inconsistent;
names := []
names.Insert("Mary")
names.Remove("Mary") ; won't work, as remove bases on indexes
This 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.

  • Guests
  • Last active:
  • Joined: --

Even already implemented Methods seem to be inconsistent;

; Compare
names.Insert(1, "Mary")
names.Remove(1)
; to
names.Insert("Mary") ; Push
names.Remove()       ; Pop


trismarck
  • Members
  • 390 posts
  • Last active: Nov 25 2015 12:35 PM
  • Joined: 02 Dec 2010

+1 for .keyCount() (count of numeric and non-numeric keys combined).


New Autohotkey forum: http://ahkscript.org.


AHK Johns
  • Members
  • 26 posts
  • Last active: Jan 12 2014 05:46 AM
  • Joined: 23 Oct 2013

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.



joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Jul 18 2017 06:01 PM
  • Joined: 20 May 2012
For reference purposes :
ObjCount(Obj) {
	if (!IsObject(Obj))
		return 0
	z:=0
	for k in Obj
		z+=1 ;or z:=A_Index
	return z
}

Why ahkscript.org? - autohotkey.com is outdated