Which of the 2 numbers are closer to 0

Hello

This could be a general question, I would ask you to help on the forum.

I am running a script and I have a function that receives 2 numbers (variables)

I would like to know which of the 2 is closer to 0

That is, if the numbers are 5, - 2 = - 2 is closer etc..

Y at - it anyone who can offer any method or function that can help me with this.

(I did 2 loops that counts how many times it took the number to get 0)

"but I think that there is a better way.)

Thank you

Davey

function minMagnitude(a, b) {
    return Math.abs(a) < Math.abs(b) ? a : b;
}

If you are not familiar with this syntax, here is another equivalent method:

function minMagnitude(a, b) {
    if (Math.abs(a) < Math.abs(b)) {
        return a;
    } else {
        return b;
    }
}

And here's another equivalent method:

function minMagnitude(a, b) {
    var absA;
    if (a < 0) {
        absA = -a;
    } else {
        absA = a;
    }

    var absB;
    if (b < 0) {
        absB = -b;
    } else {
        absB = b;
    }

    if (absA < absB) {
        return a;
    } else {
        return b;
    }
}

But really, I would stick with the first.

Tags: InDesign

Similar Questions

  • -A file association problem exist, which prevents the file you are trying to download from being associated with the correct application of the operating system using the windows 7 IE 11

    --Is a file association problem, which prevents the file you are trying to download from being associated with the correct application of the operating system

    IN USING THE WINDOW 7 IE 11 HOW CAN I FIX IT?

    Try to download the installation offline programs:

  • My camera has reached 9999 photos and started renumbering 0001 but in a different folder.  If I import new photos in iPhoto, the older photos with the same numbers are overwritten?

    My camera is renumbering pictures from 0001, but a new camera case.  If I import new photos in iPhoto, they replace the old photos with the same numbers?  The camera knows that they are in a different folder, but what happens when I import into iPhoto?

    iPHoto manages very well duplicate file names - each import is in another folder in the database - no problem

    LN

  • A way to tell which projects the "used" bits are used?

    Hello

    I have clips that show that parts are 'used' in a project. Is it possible to tell which project they are used in?

    The best

    Elmer

    CClips showing used trademarks apply only to the active project in the timeline panel. Projects switch and used different brands will probably appear.

  • Why the same numbers are used every day for 4 updates

    Whenever I have shut down my computer, I get a message saying that 4 updates are being installed.  I checked my updates and they are the same 4 updates every day.  What gives?

    Here are a few ideas:

    Audit of the newspaper is not a bad idea. but it is likely that the update log has been accumulated since XP was installed, is probably quite large, overwhelming and intimidating to see.

    I can assure you about that nobody wants to watch a huge log file with a bunch of junk in it.

    You might stop the Automatic Update Service, rename or delete the log and restart the Service to get a new connection, but even when there is 'nothing to do', the journal is full of junk that is difficult to interpret.

    Since updates .NET Framework are connected and these updates are well known for installation problems, an option is to clear the log, just choose an update - say KB982168 and try to install it manually and then you can watch what is happening, and if you have disabled your front update log file It can be easier to spot the problem.

    There is little help that particular article KB, but sometimes the .net Framework updates are particularly bothersome - perhaps other previously botched updates, malware, or other reasons.

    The best thing to do when fail it these sorts of updates of .NET Framework (minimizing the frustration) is often just uninstall all the stuff of the .NET Framework and install everything again from scratch (after checking that there is no malicious software on the system).

    We know absolutely zero about this system because the MS Answers forums does not prompt for any information system when a new question is asked.  Well, we actually know a little bit of things - it's a computer.  Do not know information difficult troubleshooting.

    Hear me, people of MS Answers?

    If you check the links in the article of Microsoft KB for some other updates, like KB979909, you can read that Microsoft has free help and support for these and all security updates - and sometimes, they are actually quite helpful and responsive.

    There are several support options, including a toll free number for especially by using the security updates that fail to install.

  • In the VI library OR: extract, control of the channel numbers are loaded automatically every time that the VI is open with "count to five: a 2 three 4.0 five." Whence this string of data?

    Even after the removal of the string "count to five: a 2 3 4.» 5."since the control of the chain and its replacement by another string, the original string returns after that the VI has been saved then reopened. Whence this string of data? I have attached a copy of the library feature. In my application, I was able to work around the problem by replacing the chain with a constant string control. But I'm still curious to know what is happening.

    Thank you
    Chuck

    Chuck,

    Chain drive was scheduled by default with the string you see.  To change it, enter the new string, right-click on the control and select

    Operations on the data > default font of the current value

    Now, save your vi.

  • When you print a postage label, the numbers are missing

    When I print a label for the U.S. postal service, some of the tracking numbers are missing.  How can I fix it?

    Thank you

    Hello

    Try to use Print as Image option in the advanced settings of the print dialog box.

    Thank you

    Abhishek

  • Change the Page numbers in the index

    Hello

    I have a catalog and I added two pages in the middle of the catalog. Now, due to the addition of two pages, I need to update the page numbers on the index with the new page numbers. I only need to increase each of the page by two numbers, but that starts only at a certain point. Thus, for example, on one of the index I have, 1-70 page numbers may remain the same, since the two extra pages were added AFTER page 70. But every number after 70 must increase by 2.

    I have a find and replace script. I create a table in excel and drop into the document. The script then takes any word or number that is listed in column A and replace it with what is in column B. I used initially this script to find and replace in the catalog product codes, and it worked great, because all the product codes were quite unique.

    Try to use this same script to change the page numbers, but she totally fizzled. The problem is that the same number is repeated later in the table, so the script has the table constantly replace all numbers with the first two. So, here is a small sample of my table:

    Col Col B

    423 425

    422 424

    421 423

    420 422

    But when I run the script, here is what it will turn into:

    Col Col B

    423 becomes 425 425

    422 becomes 424 424

    421 becomes 425 423 becomes 425

    420 becomes 424 422 becomes 424

    Because it alters the table, all corresponding numbers in the document then will increase to 425 or 424.

    Is there a way to ensure that the script does not change the information in the table that she uses as a reference?

    Here is the script below. I didn't write (makes a very nice person on these forums) and don't know anything about the scripts.

    the_table = app.selection [0] .tables [0];
    app.findChangeTextOptions = null;
    with (app.findChangeTextOptions)
    {
    caseSensitive = true;
    wholeWord = true;
    }
    app.findTextPreferences = null;
    app.changeTextPreferences = null;
    for (row = 0; row < the_table.rows.length; line ++)
    {
    If (the_table.rows [row] .cells [0] .silence == ")
    continue;
    app.findTextPreferences.findWhat = the_table.rows [row] .cells [0] .silence;
    app.changeTextPreferences.changeTo = the_table.rows [row] .cells [1] .silence;
    app.activeDocument.changeText ();
    }

    Thank you very much!

    It should work, but make sure you do backup first. I'm not going to say once: first make a backup copy. Yes, I said that you should make a backup first!

    Copy the following script, paste it into an editor appropriate - Adobe ESTK which comes with InDesign is good enough. Save it as "omgwrongnumbers.jsx" in your user Scripts folder. Select as little text as possible, the script will be blindly increment (or decrement) all numbers in the range. And then double-click the script runs.

    //DESCRIPTION:omg the page numbers are all wrong!
    // A Jongware Script 18-Aug-2010
    if (app.documents.length == 0)
    {
         alert ("Oh give me some text to play with :'(");
         exit(0);
    }
    if (app.selection.length != 1)
    {
         alert ("We can't go on like this. Select some text first.");
         exit(0);
    }
    
    myDialog = app.dialogs.add ({name:"omg the numbers are wrong!",canCancel:true});
    
    with (myDialog)
    {
         with (dialogColumns.add())
         {
              with (dialogRows.add())
                   staticTexts.add ({staticLabel:"First to change"});
              with (dialogRows.add())
                   aBox = integerEditboxes.add({editContents:"1"});
              with (dialogRows.add())
                   staticTexts.add ({staticLabel:"Last to change"});
              with (dialogRows.add())
                   bBox = integerEditboxes.add({editContents:"99999"});
              with (dialogRows.add())
                   staticTexts.add ({staticLabel:"Add or subtract this value"});
              with (dialogRows.add())
                   cBox = integerEditboxes.add({editContents:"2"});
         }
    }
    if (!myDialog.show())
    {
         myDialog.destroy();
         exit(0);
    }
    first = aBox.editValue;
    last = bBox.editValue;
    step = cBox.editValue;
    
    if (first < 1 || first > last || step == 0)
    {
         alert ("Now you're pulling my nose arentya");
         exit(0);
    }
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = "\\b\\d+\\b";
    list = app.selection[0].findGrep(true);
    changes = 0;
    for (i=0; i= first && n <= last)
              changes++, list[i].contents = String(n+step);
    }
    alert ("Number of changes: "+changes);
    
  • Finding and fixing of the sequences that are out of sync

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production version

    Hello

    Recently, our development database has been updated with production data, but have not been copied from the sequence.

    Then of course the sequence numbers are very badly synchronized with the primary key for tables throwing errors in primary key.

    How can I find the sequence names, names of tables, columns in primary key, and max values for the primary key columns that have values of key primary school max who are higher than the nextval of their corresponding sequences?

    So far the nextval of sequence numbers were all less than the max value for the primary key for the corresponding tables.

    We used the method:

    SELECT max (primary key column)

    TABLE;

    SELECT sequence_name.nextval FROM dual;

    Sequence_name ALTER SEQUENCE increment primary key value - current value of sequence max + 1;

    SELECT sequence_name.nextval FROM dual;

    SEQUENCE Sequence_name CHANGE INCREMENT OF 1;

    But this is done when a record is inserted into a table and the error is thrown.

    So I hope there is a much better way to remedy.

    Please leave me a question.

    Thank you

    Joe

    I don't know if this will help you or not, but here is what I used for the synchronization to the top of my sequences during the last upgrade/server database migration, I was involved with. You must be logged under the scheme that sequences need synchronization, linking of data back to the database, you are basing the sequences on and then let go and recreate sequences. It essentially creates a couple of other scripts and then executes them.

    CREATE DATABASE LINK dblink
    CONNECT to & schema
    IDENTIFIED BY "& password»
    USING ' & dbname';

    set pages 0;
    left head;
    Set feedback off;
    Set trimspool
    fixed line 1000;

    coil gen_seq_grants_spoolfile.sql

    Select 'grants'. privilege: ' on ' | table_name |' to ' | dealer | « ; »
    to user_sequences us,
    USER_TAB_PRIVS PAO
    where us.sequence_name = dtp.table_name;

    spool off;

    coil gen_seq_spoolfile.sql

    Select 'remove the sequence'. o.object_name | ';' | Chr (10) | Chr (10) |
    ' create the sequence ' | o.object_name | Chr (10) |
    "Start by ' | '. (to_number (s.last_number) + s.increment_by) | Chr (10) |
    "maxvalue ' | s.MAX_VALUE | Chr (10) |
    "minvalue ' | s.MIN_VALUE | Chr (10) |
    "nocycle | Chr (10) |
    'cache'. largest (s.cache_size, 20). Chr (10) |
    "all." Chr (10)
    of dba_objects@dblink o,.
    s dba_sequences@dblink,
    USER_SEQUENCES us
    where o.owner = user
    and o.object_name = s.sequence_name
    and o.owner = s.sequence_owner
    and s.sequence_name = us.sequence_name
    and o.object_type = 'SEQUENCE '.
    and us.last_number< s.last_number="" +="">
    order of o.object_name;

    spool off;

    Set of feedback

    @gen_seq_spoolfile.sql
    @gen_seq_grants_spoolfile.sql

    Drop database link dblink;

  • Premiere Elements discs and region of serial numbers are locked?

    I think buying items 14 Amazon first because I buy a lot of stuff out there. The problem is that I am from Australia and I would technically be buying an American copy. So I was wondering if the discs and serial numbers are region locked? An American copy would work for me if I live in Australia? Thank you.

    Hello, I'm from the New Zealand, but currently living in Uganda!

    There will be no problem with the disc is readable, but the serial numbers are for local use.

    The easiest thing for you to do is to buy through Adobe.com and download it from the Adobe site as well.

    Buy locally...

    Thanks for the heads up ATR...

    Seasons Greetings everyone Uganda!

  • I was wondering if I'm looking for something which exists not-firefox can automatically close the "Print preview" window after printing?

    I use the addon in my firefox toolbar to print an excerpt from the data of the Web site and then add it to a pdf file. Sometimes I'm distracted, then do not remember if I went through the process and print/added the page in the file. It would be useful if there was a way that the print preview window closes after printing which confirms that the process is complete. Thanks in advance.

    You're right: print preview remains open until the licensee. As a person who is regularly using the ESC key to dismiss dialog boxes, I had not really noticed an extra step.

    After a little research, it triggered a few times over the years (at least 2 identified bugs) but one was rejected immediately and the other has not attracted a serious debate since it was filed in 2006. I think that there are no secret switch in the software to do this.

  • Windows says FireFox must be updated but cannot be because the two instances are running, which is not true. It happens everytime I open FireFox

    Windows says FireFox must be updated but cannot be because the two instances are running, which is not true. It happens everytime I open FireFox

    This has happened

    Each time Firefox opened

    == June 28 2010

    Firefox 3.6.6 came out on 26/06/2010 to solve problems that some were plagued with the new crash protection feature introduced in Firefox 3.6.4. NOTE: Version 3.6.5 has been used for another product, so there is a "jump" in the version numbers.

    You need to update to the latest version, Firefox 3.6.6.

  • Cannot find what code product of numbers are on the label. Help, please

    may not know what are the numbers are the code of the product on the label

    Hello

    It's actually a compiled response someone put in place and I would attribute it - but I forgot where I copied it... such is the "internets"...

    At any rate, this describes your situation. It shows where the key is to Office and Windows and how to tell the difference. You don't mention which key you were talking about, so it covers all the basics:

    "1. you just installed Office in a retail box you just bought?  If Yes, go to control panel, programs and features programs and see if there is another copy of Office installed in addition to the suite that you have just installed.  Some pre-installed trial Office 2007 suites may conflict with the product key validation process.  If you see a copy of Office installed, then uninstall it and try to run your new new Office program.  Chances are that your product key now works.
    2. If you use the 25-digit product key that you found on a sticker on the bottom of your laptop or on the back of your desktop, then you are using the wrong key.  This key is the product key for the Windows operating system and NOT for the Office Suite.  The correct product key for the Office suite will be in one of these places:
    a. within the Cabinet Office 2007 (if you purchased Office in a retail store)
    b. inside an e-mail on the site online where you purchased Office
    c outside of the CD, on a sticker
     
    Microsoft has an article in the knowledge base that goes more in depth in the scenario of valid product key.  It is located at http://support.microsoft.com/kb/836178 and would be a good place to go if the instructions above do not resolve your problem.

    Hope this helps,

    Steve <> Microsoft Partner

  • How to get the new activation key when some numbers are taken away and you have received?

    How to get the new activation key when some numbers are taken away and you have received?

    Have a laptop with windows 7 from Dell. Need to re install W7. And I have some numbers are taken as a result of its use.
    How can I get a new code activation or my complete activation code?
    Best regards, W7 user

    How to get the new activation key when some numbers are taken away and you have received?


    Have a laptop with windows 7 from Dell. Need to re install W7. And I have some numbers are taken as a result of its use.
    How can I get a new code activation or my complete activation code?

    Dell provided you with restore/recovery media and/or a way to restore the machine 'default' as a key sequence?  If so - you won't need the number--unless they just sent a DVD of Windows 7 nu - and they are usually not unless you ask.

    They have probably installed using their key, which means that even with a utility like Belarc Advisor or ProduKey - you will not get the product key that matches the one on the sticker.

    Some may have you take several different digital pictures of the sticker from different angles and see if you can decipher the missing characters like that (you'd be surprised to see how that works).

  • validate if the numbers are multiples

    I need validate if two numbers are multiple.

    I am trying:

    If (selectedRow.GetAttribute ("QtyPerBox") %selectedRow.getAttribute ("QtyPerBox") == 0) { }

    continue

    }

    but selectedRow.getAttribute ("QtyPerBox") is an object. How I resolv this?

    Ensure the solution: the toString user who opposes and convert the string to an int value:

    Integer.parseInt(selectedRow.getAttribute("QtyPerBox") .toString())
    

    not so secure solution: do a cast to the Type in which the attribute is declared in JDev (including ich, a certain number of type if all goes well)

    ((Number)selectedRow.getAttribute("QtyPerBox")).intValue()
    

    Good bye

    DPT

Maybe you are looking for

  • Can I TEXT on my SKYPE number?

    I do a phone to friends and aso call send a TEXT message to a friend's mobile phone, very often. But is it possible I can get text messages on my SKYP number?

  • File 'mig' data transfer Assistant

    (Working on the Sprint this morning online customer service, but they have quickly exhausted their standard options and do not know how to help me). I ran the data transfer Assistant to my pre.  I have Outlook 2007 (the previous one had a Treo 700 p)

  • Recharge Sansa C240

    My new camera uses an AC adapter USB cable plugs on recharge the Li dough - can do us the same with the battery in the C240? Thank you

  • Scrolling ListDialog problem

    Hi all I just created a simple application with ListDialog - code comes from docs (https://developer.blackberry.com/air/documentation/bb10/create_popup_list_dialog.html) package { import flash.display.Sprite; import flash.events.MouseEvent; import qn

  • Q_PROPERTY

    I'm confused about Q_PROPERTY can any body tell what "Q_PROPERTY (QString text text READ WRITE setText NOTIFY textChanged)" means