[Jspro-cvs] jsPro validator.js,NONE,1.1 string.js,1.17,1.18 array.js,1.25,1.26
Brought to you by:
wigleys
|
From: <wi...@us...> - 2003-09-19 20:24:25
|
Update of /cvsroot/jspro/jsPro
In directory sc8-pr-cvs1:/tmp/cvs-serv9968
Modified Files:
string.js array.js
Added Files:
validator.js
Log Message:
various new methods - see CHANGES for details
--- NEW FILE: validator.js ---
/**
* +-------------------------------------------------------------------------+
* | jsPro - Validator |
* +-------------------------------------------------------------------------+
* | Copyright (C) 2001-2003 Stuart Wigley |
* +-------------------------------------------------------------------------+
* | This library is free software; you can redistribute it and/or modify it |
* | under the terms of the GNU Lesser General Public License as published by|
* | the Free Software Foundation; either version 2.1 of the License, or (at |
* | your option) any later version. |
* | |
* | This library is distributed in the hope that it will be useful, but |
* | WITHOUT ANY WARRANTY; without even the implied warranty of |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
* | General Public License for more details. |
* | |
* | You should have received a copy of the GNU Lesser General Public License|
* | along with this library; if not, write to the Free Software Foundation, |
* | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* +-------------------------------------------------------------------------+
* | Authors: Stuart Wigley <stu...@ya...> |
* +-------------------------------------------------------------------------+
* $Id: validator.js,v 1.1 2003/09/19 15:44:21 wigleys Exp $
*/
/**
* Creates an object that provides methods for performing boolean validations.
*
* @author Stuart Wigley
* @version 1.0, 09/19/03
* @interface <code>new Validator()</code>
*/
function Validator() { }
/**
* Test if the supplied value is a blank string or a string made up of
* whitespaces, tabs or newline characters
*
* @summary is a blank string
* @author Stuart Wigley
* @version 1.0, 09/19/03
* @interface <code>Validator.isBlankString(sValue)</code>
* @param sValue the value to test against
* @return true or false
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
* @throws TypeMismatchException
*/
Validator.prototype.isBlankString = function(sValue) {
try {
var vError = null;
var iNumArguments = arguments.length;
if (iNumArguments != 1) {
throw vError = new IllegalArgumentException('Validator.isBlankString', 1, iNumArguments);
}
if (typeof sValue != 'string') {
throw vError = new TypeMismatchException('Validator.isBlankString', 'string', typeof sValue);
}
var bIsBlankString = (sValue.match(/[\w]/g)) ? false : true;
}
catch (vError) {
if (vError instanceof Error) {
vError.handleError();
}
}
finally {
return vError ? null : bIsBlankString;
}
}
/**
* Test if the supplied value is a single digit in the range 0 to 9
*
* @summary is a single digit
* @author Stuart Wigley
* @version 1.0, 09/19/03
* @interface <code>Validator.isDigit(iValue)</code>
* @param iValue the value to test against
* @return true or false
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
* @throws TypeMismatchException
*/
Validator.prototype.isDigit = function(iValue) {
try {
var vError = null;
var iNumArguments = arguments.length;
if (iNumArguments != 1) {
throw vError = new IllegalArgumentException('Validator.isDigit', 1, iNumArguments);
}
if (typeof iValue != 'number') {
throw vError = new TypeMismatchException('Validator.isDigit', 'number', typeof iValue);
}
var bIsDigit = ((iValue < 10) && iValue.toString().length == 1) ? true : false;
}
catch (vError) {
if (vError instanceof Error) {
vError.handleError();
}
}
finally {
return vError ? null : bIsDigit;
}
}
/**
* Test if the supplied value is an integer
*
* @summary is an integer
* @author Stuart Wigley
* @version 1.0, 09/19/03
* @interface <code>Validator.isInteger(iValue)</code>
* @param iValue the value to test against
* @return true or false
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
* @throws TypeMismatchException
*/
Validator.prototype.isInteger = function(iValue) {
try {
var vError = null;
var iNumArguments = arguments.length;
if (iNumArguments != 1) {
throw vError = new IllegalArgumentException('Validator.isInteger', 1, iNumArguments);
}
if (typeof iValue != 'number') {
throw vError = new TypeMismatchException('Validator.isInteger', 'number', typeof iValue);
}
var bIsInteger = (iValue.toString().indexOf('.') == -1) ? true : false;
}
catch (vError) {
if (vError instanceof Error) {
vError.handleError();
}
}
finally {
return vError ? null : bIsInteger;
}
}
Index: string.js
===================================================================
RCS file: /cvsroot/jspro/jsPro/string.js,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** string.js 15 Sep 2003 01:51:03 -0000 1.17
--- string.js 19 Sep 2003 15:44:21 -0000 1.18
***************
*** 30,34 ****
* quotes), and reverse solidi (backslashes) in this string with backslashes.
*
! * @summary escape vertain characters with backslashes
* @author Stuart Wigley
* @author Randolph Fielding
--- 30,34 ----
* quotes), and reverse solidi (backslashes) in this string with backslashes.
*
! * @summary escape certain characters with backslashes
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 73,76 ****
--- 73,156 ----
/**
+ * Concatenate the string representation of <code>vValue</code> to the end of
+ * the current string
+ *
+ * @summary count occurrence of characters
+ * @author Stuart Wigley
+ * @version 1.0, 09/19/03
+ * @interface <code>String.cat(vValue)</code>
+ * @param vValue value to be concatenated to end of string
+ * @return concatenated string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ */
+ String.prototype.cat = function(vValue) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('String.cat', 1, iNumArguments);
+ }
+
+ var sValue = arguments[0].toString();
+ var sCatString = this + sValue;
+
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sCatString;
+ }
+ }
+
+
+ /**
+ * Replaces all Unix, Windows and Macintosh newline characters, tabs and
+ * repeated spaces with a single space character.
+ *
+ * @summary compress to spaces
+ * @author Stuart Wigley
+ * @version 1.0, 09/19/03
+ * @interface <code>String.compress()</code>
+ * @return a modified string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ */
+ String.prototype.compress = function() {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+ var iDocType = 1;
+
+ if (iNumArguments != 0) {
+ throw vError = new IllegalArgumentException('String.compress', 0, iNumArguments);
+ }
+
+ var sModifiedString = this.replace(/(\r\n)|(\r)|(\n)|(\t)|(\s+)/g, ' ');
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sModifiedString;
+ }
+ }
+
+
+ /**
* Returns an associative array keyed on the characters of this string. Each
* member of the associative array contains an integer value representing the
***************
*** 244,247 ****
--- 324,390 ----
/**
+ * Inserts a string into another string at the specified position
+ *
+ * @summary insert a string
+ * @author Stuart Wigley
+ * @version 1.0, 09/19/03
+ * @interface <code>String.insert(sInsert)</code>
+ * @interface <code>String.insert(sInsert, iStart)</code>
+ * @param sInsert the string to be inserted
+ * @param iStart the position where the insert should begin
+ * @return a modified string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ */
+ String.prototype.insert = function() {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+ var sInsert = '';
+ var iStart = 0;
+ var iLength = this.length;
+
+ if (iNumArguments == 1) {
+ sInsert = arguments[0];
+ } else if (iNumArguments == 2) {
+ sInsert = arguments[0];
+ iStart = arguments[1];
+ } else {
+ throw vError = new IllegalArgumentException('String.insert', '1 or 2', iNumArguments);
+ }
+
+ if (typeof sInsert != 'string') {
+ throw vError = new TypeMismatchException('String.insert', 'string', typeof sInsert);
+ }
+ if ((typeof iStart != 'number') || (parseInt(iStart.toString()) != iStart)) {
+ throw vError = new TypeMismatchException('String.insert', 'number', typeof iStart);
+ }
+
+ var sModifiedString = '';
+
+ for (var i = 0; i < iLength; i++) {
+ if (i == iStart) {
+ sModifiedString += sInsert;
+ }
+ sModifiedString += this.charAt(i);
+ }
+
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sModifiedString;
+ }
+ }
+
+
+ /**
* Tests this string with a regular expression for standard email address
* compliance.
***************
*** 537,540 ****
--- 680,747 ----
/**
+ * Overlays a string over another string at the specified position
+ *
+ * @summary overlay a string
+ * @author Stuart Wigley
+ * @version 1.0, 09/19/03
+ * @interface <code>String.overlay(sInsert)</code>
+ * @interface <code>String.overlay(sInsert, iStart)</code>
+ * @param sOverlay the string to be overlayed
+ * @param iStart the position where the overlay should begin
+ * @return a modified string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ */
+ String.prototype.overlay = function() {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+ var sOverlay = '';
+ var iStart = 0;
+ var iLength = this.length;
+
+ if (iNumArguments == 1) {
+ sOverlay = arguments[0];
+ } else if (iNumArguments == 2) {
+ sOverlay = arguments[0];
+ iStart = arguments[1];
+ } else {
+ throw vError = new IllegalArgumentException('String.overlay', '1 or 2', iNumArguments);
+ }
+
+ if (typeof sOverlay != 'string') {
+ throw vError = new TypeMismatchException('String.insert', 'string', typeof sOverlay);
+ }
+ if ((typeof iStart != 'number') || (parseInt(iStart.toString()) != iStart)) {
+ throw vError = new TypeMismatchException('String.insert', 'number', typeof iStart);
+ }
+
+ var sModifiedString = '';
+
+ for (var i = 0; i < iLength; i++) {
+ if (i == iStart) {
+ sModifiedString += sOverlay;
+ i += sOverlay.length;
+ }
+ sModifiedString += this.charAt(i);
+ }
+
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sModifiedString;
+ }
+ }
+
+
+ /**
* Pads either both sides, the left side, or the right side of this string
* with another string for a specified number of times.
***************
*** 614,617 ****
--- 821,883 ----
/**
+ * Removes all characters from the string or a subset of characters (if the
+ * optional start and end arguments are specified)
+ *
+ * @summary delete characters
+ * @author Stuart Wigley
+ * @version 1.0, 09/19/03
+ * @interface <code>String.remove()</code>
+ * @interface <code>String.remove(iStart)</code>
+ * @interface <code>String.remove(iStart, iEnd)</code>
+ * @param iStart the string position to start at (optional)
+ * @param iEnd the string position to end at (optional)
+ * @return the modified string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ */
+ String.prototype.remove = function() {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+ var iStart = 0;
+ var iEnd = this.length + 1;
+
+ if (iNumArguments > 2) {
+ throw vError = new IllegalArgumentException('String.remove', '0, 1 or 2', iNumArguments);
+ } else if (iNumArguments == 2) {
+ iStart = arguments[0];
+ iEnd = arguments[1];
+ } else if (iNumArguments == 1) {
+ iStart = arguments[0];
+ }
+
+ if ((typeof iStart != 'number') || (parseInt(iStart.toString()) != iStart)) {
+ throw vError = new TypeMismatchException('String.remove', 'number', typeof iStart);
+ }
+
+ if ((typeof iEnd != 'number') || (parseInt(iEnd.toString()) != iEnd)) {
+ throw vError = new TypeMismatchException('String.remove', 'number', typeof iEnd);
+ }
+
+ var sSubString = this.slice(iStart, iEnd);
+ var oRegExp = new RegExp(sSubString);
+ var sDeleted = this.replace(oRegExp, '');
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sDeleted;
+ }
+ }
+
+
+ /**
* Repeats this string a specified number of times.
*
***************
*** 662,665 ****
--- 928,982 ----
/**
+ * Repeats this string a specified number of times.
+ *
+ * @summary repeat
+ * @author Stuart Wigley
+ * @author Randolph Fielding
+ * @version 1.1, 08/04/03
+ * @interface <code>String.repeat(iMultiplier)</code>
+ * @param iMultiplier the number of times to repeat this string
+ * @return a new string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ String.prototype.repeatChars = function(iMultiplier) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('String.repeatChars', 1, iNumArguments);
+ }
+
+ if ((typeof iMultiplier != 'number') || (parseInt(iMultiplier.toString()) != iMultiplier)) {
+ throw vError = new TypeMismatchException('String.repeatChars', 'number', typeof iMultiplier);
+ }
+
+ var sRepeatedString = '';
+ var iLength = this.length;
+
+ for (var i = 0; i < iLength; i++) {
+ for (var j = 0; j < iMultiplier; j++) {
+ sRepeatedString += this.charAt(i);
+ }
+ }
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sRepeatedString;
+ }
+ }
+
+
+ /**
* Reverses the order of all characters within this string or a subset of
* characters within this string (if the optional start and length arguments
***************
*** 925,928 ****
--- 1242,1288 ----
/**
+ * Swap every second character in the string
+ *
+ * @summary swap characters
+ * @author Stuart Wigley
+ * @version 1.0, 09/19/03
+ * @interface <code>String.swap()</code>
+ * @return a modified string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ */
+ String.prototype.swap = function() {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments > 0) {
+ throw vError = new IllegalArgumentException('String.swap', 0, iNumArguments);
+ }
+
+ var sModifiedString = '';
+ var iLength = this.length;
+
+ for (var i = 0; i < iLength; i += 2) {
+ sModifiedString += this.charAt(i + 1);
+ sModifiedString += this.charAt(i);
+ }
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sModifiedString;
+ }
+ }
+
+
+ /**
* Trims whitespace characters from either both sides, the left side, or the
* right side of this string.
***************
*** 976,979 ****
--- 1336,1401 ----
return vError ? null : sTrimmedString;
+ }
+ }
+
+
+ /**
+ * Truncate a string to the specified length. If specified the final three
+ * characters are replaced with an ellipsis.
+ *
+ * @summary truncate
+ * @author Stuart Wigley
+ * @version 1.0, 09/03/03
+ * @interface <code>String.truncate(iLength)</code>
+ * @interface <code>String.truncate(iEllipsis)</code>
+ * @param iLength the position at which truncation should occur
+ * @param iEllipsis replace the final three characters with an ellipsis.
+ * (yes: 1; no: 0; default: 0) (optional)
+ * @return a modified string
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ String.prototype.truncate = function() {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+ var iLength = this.length;
+ var iEllipsis = 0;
+
+ if (iNumArguments == 1) {
+ iLength = arguments[0];
+ } else if (iNumArguments == 2) {
+ iLength = arguments[0];
+ iEllipsis = arguments[1];
+ } else {
+ throw vError = new IllegalArgumentException('String.truncate', '1 or 2', iNumArguments);
+ }
+
+ if ((typeof iLength != 'number') || (parseInt(iLength.toString()) != iLength)) {
+ throw vError = new TypeMismatchException('String.truncate', 'number', typeof iLength);
+ }
+
+ var sTruncatedString = '';
+
+ for (var i = 0; i < iLength; i++) {
+ if ((iEllipsis == 1) && (iLength - i < 4)) {
+ sTruncatedString += '.';
+ } else {
+ sTruncatedString += this.charAt(i);
+ }
+ }
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : sTruncatedString;
}
}
Index: array.js
===================================================================
RCS file: /cvsroot/jspro/jsPro/array.js,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** array.js 17 Sep 2003 08:43:30 -0000 1.25
--- array.js 19 Sep 2003 15:44:21 -0000 1.26
***************
*** 27,30 ****
--- 27,134 ----
/**
+ * Calculates and returns the average deviation of all array members or of a
+ * subset of array members (if the optional start and length arguments are
+ * specified).
+ *
+ * @summary average deviation
+ * @author Stuart Wigley
+ * @version 1.0, 19/08/03
+ * @interface <code>Array.averageDev()</code>
+ * @interface <code>Array.averageDev(iStart)</code>
+ * @interface <code>Array.averageDev(iStart, iLength)</code>
+ * @requires <code>Array.mean(iStart, iLength)</code>
+ * @param iStart the index of the array member to start at (optional)
+ * @param iLength the number of array members to evaluate beginning at
+ * <code>iStart</code> (optional)
+ * @return the average deviation of all array members or of a
+ * subset of array members
+ * @return <code>null</code> if an exception is encountered
+ * @throws ArrayIndexOutOfBoundsException
+ * @throws IllegalArgumentException
+ * @throws MethodNotAvailableException
+ * @throws TypeMismatchException
+ * @throws UnknownException
+ * @see <code>Array.mean()</code>
+ */
+ Array.prototype.averageDev = function() {
+
+ try {
+
+ var vError = null;
+ var iArrayLength = this.length;
+ var iNumArguments = arguments.length;
+ var iStart = 0;
+ var iLength = iArrayLength;
+
+ if (!('mean' in this)) {
+ throw vError = new MethodNotAvailableException('Array.averageDev', 'Array.mean');
+ }
+
+ if (iNumArguments > 2) {
+ throw vError = new IllegalArgumentException('Array.averageDev', '0, 1 or 2', iNumArguments);
+ } else if (iNumArguments == 2) {
+ iStart = arguments[0];
+ iLength = arguments[1];
+ } else if (iNumArguments == 1) {
+ iStart = arguments[0];
+ iLength -= iStart;
+ }
+
+ if ((typeof iStart != 'number') || (parseInt(iStart.toString()) != iStart)) {
+ throw vError = new TypeMismatchException('Array.averageDev', 'number', typeof iStart);
+ }
+
+ if ((typeof iLength != 'number') || (parseInt(iLength.toString()) != iLength)) {
+ throw vError = new TypeMismatchException('Array.averageDev', 'number', typeof iLength);
+ }
+
+ var iEnd = iStart + iLength;
+
+ if (iStart < 0) {
+ throw vError = new ArrayIndexOutOfBoundsException('Array.averageDev', iStart, iArrayLength);
+ }
+
+ if (iLength <= 0) {
+ throw vError = new ArrayIndexOutOfBoundsException('Array.averageDev', iLength, iArrayLength);
+ }
+
+ if (iEnd > iArrayLength) {
+ throw vError = new ArrayIndexOutOfBoundsException('Array.averageDev', iEnd, iArrayLength);
+ }
+
+ var aAbsValues = new Array();
+ var iCount = 0;
+ var faverageDev = null;
+
+ var fMean = this.mean(iStart, iEnd);
+
+ if (!fMean) {
+ throw vError = new UnknownException('Array.averageDev');
+ }
+
+ for (var i = iStart; i < iEnd; i++) {
+ if (typeof this[i] == 'number') {
+ aAbsValues[iCount] = (Math.abs(this[i] - fMean));
+ iCount++;
+ }
+ }
+
+ var faverageDev = aAbsValues.mean();
+
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : faverageDev;
+ }
+ }
+
+
+ /**
* Changes the case of all array keys to lowercase or uppercase.
*
***************
*** 198,202 ****
* @interface <code>Array.covar(iStart, iLength)</code>
* @requires <code>Array.mean(iStart, iLength)</code>
! * @requires <code>Array.stdev(iStart, iLength)</code>
* @param iStart the index of the array member to start at (optional)
* @param iLength the number of array members to evaluate beginning at
--- 302,306 ----
* @interface <code>Array.covar(iStart, iLength)</code>
* @requires <code>Array.mean(iStart, iLength)</code>
! * @requires <code>Array.standardDev(iStart, iLength)</code>
* @param iStart the index of the array member to start at (optional)
* @param iLength the number of array members to evaluate beginning at
***************
*** 211,215 ****
* @throws UnknownException
* @see <code>Array.mean()</code>
! * @see <code>Array.stdev()</code>
*/
Array.prototype.covar = function() {
--- 315,319 ----
* @throws UnknownException
* @see <code>Array.mean()</code>
! * @see <code>Array.standardDev()</code>
*/
Array.prototype.covar = function() {
***************
*** 227,232 ****
}
! if (!('stdev' in this)) {
! throw vError = new MethodNotAvailableException('Array.covar', 'Array.stdev');
}
--- 331,336 ----
}
! if (!('standardDev' in this)) {
! throw vError = new MethodNotAvailableException('Array.covar', 'Array.standardDev');
}
***************
*** 264,274 ****
var fMean = this.mean(iStart, iLength);
! var fStDev = this.stdev(iStart, iLength);
! if (!fMean || !fStDev) {
throw vError = new UnknownException('Array.covar');
}
! var fCovar = fStDev / fMean;
}
catch (vError) {
--- 368,378 ----
var fMean = this.mean(iStart, iLength);
! var fstandardDev = this.standardDev(iStart, iLength);
! if (!fMean || !fstandardDev) {
throw vError = new UnknownException('Array.covar');
}
! var fCovar = fstandardDev / fMean;
}
catch (vError) {
***************
*** 923,929 ****
* @author Randolph Fielding
* @version 1.4, 08/08/03
! * @interface <code>Array.stdev()</code>
! * @interface <code>Array.stdev(iStart)</code>
! * @interface <code>Array.stdev(iStart, iLength)</code>
* @requires <code>Array.variance(iStart, iLength)</code>
* @param iStart the index of the array member to start at (optional)
--- 1027,1033 ----
* @author Randolph Fielding
* @version 1.4, 08/08/03
! * @interface <code>Array.standardDev()</code>
! * @interface <code>Array.standardDev(iStart)</code>
! * @interface <code>Array.standardDev(iStart, iLength)</code>
* @requires <code>Array.variance(iStart, iLength)</code>
* @param iStart the index of the array member to start at (optional)
***************
*** 940,944 ****
* @see <code>Array.variance()</code>
*/
! Array.prototype.stdev = function() {
try {
--- 1044,1048 ----
* @see <code>Array.variance()</code>
*/
! Array.prototype.standardDev = function() {
try {
***************
*** 951,959 ****
if (!('variance' in this)) {
! throw vError = new MethodNotAvailableException('Array.stdev', 'Array.variance');
}
if (iNumArguments > 2) {
! throw vError = new IllegalArgumentException('Array.stdev', '0, 1 or 2', iNumArguments);
} else if (iNumArguments == 2) {
iStart = arguments[0];
--- 1055,1063 ----
if (!('variance' in this)) {
! throw vError = new MethodNotAvailableException('Array.standardDev', 'Array.variance');
}
if (iNumArguments > 2) {
! throw vError = new IllegalArgumentException('Array.standardDev', '0, 1 or 2', iNumArguments);
} else if (iNumArguments == 2) {
iStart = arguments[0];
***************
*** 965,973 ****
if ((typeof iStart != 'number') || (parseInt(iStart.toString()) != iStart)) {
! throw vError = new TypeMismatchException('Array.stdev', 'number', typeof iStart);
}
if ((typeof iLength != 'number') || (parseInt(iLength.toString()) != iLength)) {
! throw vError = new TypeMismatchException('Array.stdev', 'number', typeof iLength);
}
--- 1069,1077 ----
if ((typeof iStart != 'number') || (parseInt(iStart.toString()) != iStart)) {
! throw vError = new TypeMismatchException('Array.standardDev', 'number', typeof iStart);
}
if ((typeof iLength != 'number') || (parseInt(iLength.toString()) != iLength)) {
! throw vError = new TypeMismatchException('Array.standardDev', 'number', typeof iLength);
}
***************
*** 975,987 ****
if (iStart < 0) {
! throw vError = new ArrayIndexOutOfBoundsException('Array.stdev', iStart, iArrayLength);
}
if (iLength <= 0) {
! throw vError = new ArrayIndexOutOfBoundsException('Array.stdev', iLength, iArrayLength);
}
if (iEnd > iArrayLength) {
! throw vError = new ArrayIndexOutOfBoundsException('Array.stdev', iEnd, iArrayLength);
}
--- 1079,1091 ----
if (iStart < 0) {
! throw vError = new ArrayIndexOutOfBoundsException('Array.standardDev', iStart, iArrayLength);
}
if (iLength <= 0) {
! throw vError = new ArrayIndexOutOfBoundsException('Array.standardDev', iLength, iArrayLength);
}
if (iEnd > iArrayLength) {
! throw vError = new ArrayIndexOutOfBoundsException('Array.standardDev', iEnd, iArrayLength);
}
***************
*** 989,996 ****
if (!fVariance) {
! throw vError = new UnknownException('Array.stdev');
}
! var fStDev = Math.sqrt(fVariance);
}
catch (vError) {
--- 1093,1100 ----
if (!fVariance) {
! throw vError = new UnknownException('Array.standardDev');
}
! var fstandardDev = Math.sqrt(fVariance);
}
catch (vError) {
***************
*** 1002,1006 ****
finally {
! return vError ? null : fStDev;
}
}
--- 1106,1110 ----
finally {
! return vError ? null : fstandardDev;
}
}
|