n3ss3s
2007-11-16 09:38:56
I noticed that there aren't some math functions in SCAR
(yes I know they + these aren't all)
and I quickly made couple simple, but maybe useful for someone
1. Median - in Finnish the name is Mediaani, so I think its something like Median.
It returns the value in middle of the array after rearranging from small to large.
If the array size is even, it gets the two middlest and divides by two.
I decided to post these here instead of my own function thread, because these could be called 'core functions' or like that, not my custom obj finders lol.
Hope they make someones life easier :)
(yes I know they + these aren't all)
and I quickly made couple simple, but maybe useful for someone
1. Median - in Finnish the name is Mediaani, so I think its something like Median.
It returns the value in middle of the array after rearranging from small to large.
If the array size is even, it gets the two middlest and divides by two.
Function Median(Ints: TIntegerArray): Extended;
Var
I: Integer;
Begin
BubbleSort(Ints);
I := GetArrayLength(Ints);
If I Mod 2 <> 0 Then
Begin
Result := Ints[Round(High(Ints) / 2)];
End Else
Begin
Result := (Ints[Round(High(Ints) / 2)-1] + Ints[Round(High(Ints) /2)]) / 2;
End;
End;
Function Average(Ints: TIntegerArray): Extended;
Var
I: Integer;
Begin
For I := 0 To High(Ints) Do
Begin
Result := Result + Ints[i];
End;
Result := Result / GetArrayLength(Ints);
End;
Function InIntArrayArray(Ints: Array of TIntegerArray; Value: Integer): Boolean;
Var
I: Integer;
Begin
For I := 0 To High(Ints) Do
Begin
If InIntArray(Ints[i], Value) Then
Begin
Result := True;
Exit;
End;
End;
End;
Function InIntArrayArrayEx(Ints: Array of TIntegerArray; Var TheArray: Integer; Value: Integer): Boolean;
Var
I: Integer;
Begin
For I := 0 To High(Ints) Do
Begin
If InIntArray(Ints[i], Value) Then
Begin
Result := True;
TheArray := I;
Exit;
End;
End;
End;
I decided to post these here instead of my own function thread, because these could be called 'core functions' or like that, not my custom obj finders lol.
Hope they make someones life easier :)