Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 A Testing Area
 Testing Forums
 test scrollcode here
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TSAloha
Junior Member

USA
151 Posts

Posted - 04 April 2011 :  22:04:40  Show Profile  Reply with Quote
This is a test post with a random js codes for scrollcode.


/* 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"); // exception throwing
}
return x;
};
this.a = checkInt(x)
// ^ semicolons are optional (but beware since this may cause consecutive lines to be
//erroneously treated as a single statement)
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;
},
"lcm" /* can use strings here */: 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;
}
};

// Note: Array's map() and forEach() are predefined in JavaScript 1.6.
// They are currently not available in the JScript engine built into
// Microsoft Internet Explorer, but are implemented in Firefox, Chrome, etc.
// 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) {
/* Note: print() is a JS builtin function available in Mozilla's js CLI;
* It is functionally equivalent to Java's System.out.println().
* Within a web browser, print() is a very different function
* (opens the "Print Page" dialog),
* so use something like document.write() or alert() instead.
*/
// print (obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
// alert (obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
document.write(obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm() + "<br>");
});




Edited by - TSAloha on 05 May 2011 17:01:19

herry
Starting Member

USA
5 Posts

Posted - 03 May 2011 :  04:04:48  Show Profile  Reply with Quote
what is this i can't understand which type of test it is???

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 03 May 2011 :  04:51:43  Show Profile  Send ruirib a Yahoo! Message  Reply with Quote
herry,

Please stop trying to put your link in every post you make. I don't want to think you are just trying to boost your sales website.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.1 seconds. Powered By: Snitz Forums 2000 Version 3.4.07