Js printing paper function code (recursion)

Source: Internet
Author: User

Copy codeThe Code is as follows:
// Print size, in MM
// Http://en.wikipedia.org/wiki/ISO_216
Var page = function (){
Var A0 = {name: "A0", width: 841, height: 1189}; // unit: MM
Var B0 = {name: "B0", width: 1000, height: 1414}; // unit: MM
Var C0 = {name: "C0", width: 917, height: 1297}; // unit: MM
// Obtain the previous Specification
Function getPrefixSize (name ){
Var list = name. split ('');
Var series = list [0];
Var number = parseInt (list [1]);
If (! IsNaN (number) & number> 0 ){
Return series + (number-1 );
}
}
// Obtain the size of the Specification
Function getSize (name ){
If (name = "C7/6 "){
Return {name: "C7/6", width: 81, height: 162 };
}
Var list = name. split ('');
Var series = list [0];
Var number = parseInt (list [1]);
If (isNaN (number )){
Return;
}
If (number = 0 ){
If (series = "A") {return A0 ;}
Else if (series = "B") {return B0 ;}
Else if (series = "C") {return C0 ;}
}
Return {name: name, width: parseInt (getSize (getPrefixSize (name). height/2), height: parseInt (getSize (getPrefixSize (name). width )};
}
Return {
GetSize: getSize
}
}();

Usage
Copy codeThe Code is as follows:
Page. getSize ('a4 ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.