Files
addressbook
admin
api
calendar
doc
etemplate
filemanager
files
home
importexport
infolog
mail
notifications
phpgwapi
cron
doc
images
inc
HTTP
adodb
horde
htmLawed
idna_convert
min
lib
.htaccess
config.php
groupsConfig.php
index.php
quick-test.css
quick-test.js
utils.php
savant2
class.Template.inc.php
class.about.inc.php
class.accounts.inc.php
class.accounts_ads.inc.php
class.accounts_ldap.inc.php
class.accounts_sql.inc.php
class.accounts_univention.inc.php
class.acl.inc.php
class.applications.inc.php
class.arrayfunctions.inc.php
class.asyncservice.inc.php
class.auth.inc.php
class.auth_ads.inc.php
class.auth_cas.inc.php
class.auth_fallback.inc.php
class.auth_fallbackmail2sql.inc.php
class.auth_http.inc.php
class.auth_ldap.inc.php
class.auth_mail.inc.php
class.auth_nis.inc.php
class.auth_pam.inc.php
class.auth_sql.inc.php
class.auth_sqlssl.inc.php
class.bolink.inc.php
class.categories.inc.php
class.common.inc.php
class.config.inc.php
class.contacts.inc.php
class.contenthistory.inc.php
class.country.inc.php
class.db_backup.inc.php
class.egw.inc.php
class.egw_cache.inc.php
class.egw_cache_apc.inc.php
class.egw_cache_files.inc.php
class.egw_cache_memcache.inc.php
class.egw_ckeditor_config.inc.php
class.egw_csrf.inc.php
class.egw_customfields.inc.php
class.egw_datetime.inc.php
class.egw_db.inc.php
class.egw_digest_auth.inc.php
class.egw_exception.inc.php
class.egw_favorites.inc.php
class.egw_find_iterator.inc.php
class.egw_framework.inc.php
class.egw_grid_columns.inc.php
class.egw_htmLawed.inc.php
class.egw_ical_iterator.inc.php
class.egw_idna.inc.php
class.egw_include_mgr.inc.php
class.egw_index.inc.php
class.egw_json.inc.php
class.egw_json_push.inc.php
class.egw_keymanager.inc.php
class.egw_link.inc.php
class.egw_mailer.inc.php
class.egw_session.inc.php
class.egw_session_files.inc.php
class.egw_session_memcache.inc.php
class.egw_sharing.inc.php
class.egw_tail.inc.php
class.egw_time.inc.php
class.egw_vfs.inc.php
class.global_stream_wrapper.inc.php
class.groupdav.inc.php
class.groupdav_handler.inc.php
class.groupdav_hooks.inc.php
class.groupdav_principals.inc.php
class.historylog.inc.php
class.hooks.inc.php
class.html.inc.php
class.iface_stream_wrapper.inc.php
class.ischedule_client.inc.php
class.ischedule_server.inc.php
class.jscalendar.inc.php
class.ldap.inc.php
class.ldapserverinfo.inc.php
class.log.inc.php
class.mailDomainSigner.inc.php
class.mime_magic.inc.php
class.network.inc.php
class.nextmatchs.inc.php
class.preferences.inc.php
class.schema_proc.inc.php
class.send.inc.php
class.solink.inc.php
class.sqlfs_stream_wrapper.inc.php
class.sqlfs_utils.inc.php
class.tplsavant2.inc.php
class.translation.inc.php
class.uiaccountsel.inc.php
class.vfs_home_hooks.inc.php
class.vfs_webdav_server.inc.php
common_functions.inc.php
functions.inc.php
jscalendar-setup.php
js
lang
ntlm
setup
templates
templatesSavant2
tests
addressbook.php
config.php
images.php
ischedule-cli.php
ischedule.php
lang.php
user.php
pixelegg
preferences
resources
setup
timesheet
.htaccess
about.php
composer.json
composer.lock
groupdav.htaccess
groupdav.php
header.inc.php.template
index.php
json.php
login.php
logout.php
redirect.php
remote.php
rpc.php
set_box.php
share.php
status.php
svn-helper.php
webdav.php
egroupware/phpgwapi/inc/min/quick-test.js

74 lines
2.7 KiB
JavaScript
Executable File

/*! This file exists only for testing a Minify installation. It's content is not used.
*
* http://example.org/min/f=min/quick-test.js
*/
/* Finds the lowest common multiple of two numbers */
function LCMCalculator(x, y) { // constructor function
var checkInt = function (x) { // inner function
if (x % 1 !== 0) {
throw new TypeError(x + " is not an integer"); // throw an exception
}
return x;
};
this.a = checkInt(x);
// ^ semicolons are optional
this.b = checkInt(y);
}
// The prototype of object instances created by a constructor is
// that constructor's "prototype" property.
LCMCalculator.prototype = { // object literal
constructor: LCMCalculator, // when reassigning a prototype, set the constructor property appropriately
gcd: function () { // method that calculates the greatest common divisor
// Euclidean algorithm:
var a = Math.abs(this.a), b = Math.abs(this.b), t;
if (a < b) {
// swap variables
t = b;
b = a;
a = t;
}
while (b !== 0) {
t = b;
b = a % b;
a = t;
}
// Only need to calculate GCD once, so "redefine" this method.
// (Actually not redefinition - it's defined on the instance itself,
// so that this.gcd refers to this "redefinition" instead of LCMCalculator.prototype.gcd.)
// Also, 'gcd' === "gcd", this['gcd'] === this.gcd
this['gcd'] = function () {
return a;
};
return a;
},
// Object property names can be specified by strings delimited by double (") or single (') quotes.
"lcm" : function () {
// Variable names don't collide with object properties, e.g. |lcm| is not |this.lcm|.
// not using |this.a * this.b| to avoid FP precision issues
var lcm = this.a / this.gcd() * this.b;
// Only need to calculate lcm once, so "redefine" this method.
this.lcm = function () {
return lcm;
};
return lcm;
},
toString: function () {
return "LCMCalculator: a = " + this.a + ", b = " + this.b;
}
};
//define generic output function; this implementation only works for web browsers
function output(x) {
document.write(x + "<br>");
}
// Note: Array's map() and forEach() are defined in JavaScript 1.6.
// They are used here to demonstrate JavaScript's inherent functional nature.
[[25, 55], [21, 56], [22, 58], [28, 56]].map(function (pair) { // array literal + mapping function
return new LCMCalculator(pair[0], pair[1]);
}).sort(function (a, b) { // sort with this comparative function
return a.lcm() - b.lcm();
}).forEach(function (obj) {
output(obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
});