• Learning arrays

    From Mortifis@VERT/ALLEYCAT to All on Wed Jul 17 16:09:38 2019
    So, I threw together a little script that loops through the userbase and compares email addresses no problem, however, I am having difficulty storing the user number in an array for access later on in the script; what I have tried (resulting in no list displayed.

    load("sbbsdefs.js");

    const REVISION = "$Revision: .01 $".split(' ')[1];

    print("Synchronet Duplicate Email Address Checker " + REVISION + "\r\n");

    var u; // user object
    var d;
    var dups=0;
    var recs=0;
    var dups;
    var lastuser;
    var has_dup = false;
    var dup_u =0;

    lastuser=system.lastuser;

    for(i=1; i<=lastuser; i++) // loop through users and grab the email address
    {
    u = new User(i);

    if(u.settings&(USER_DELETED|USER_INACTIVE))
    continue;

    // start new new loop and compare email addresses
    for(n=1; n<=lastuser; n++)
    {
    d = new User(n)
    if(u.number == d.number) continue;
    if(d.settings&(USER_DELETED|USER_INACTIVE)) continue;

    if(u.netmail == d.netmail)
    {
    print(u.alias + " [" + u.number + "] shares " + d.alias + " [" +
    d.number + "] ("+d.netmail+")\r");

    has_dup[i] = true;
    dup_u[dups] = i;
    dups++;
    }
    }

    recs++;
    }

    dups = dups/2; // since if one is found then 2 are found :-P

    if(dups == 1) dup = "Entry"; else dup = "Entries";

    for(y=1; y<= lastuser; y++) {
    if(has_dup[y] == true) {
    print("Dup user " + dup_u[y] + " user alias " + "alias " +u.alias[dup_u[y]]);
    }
    }

    // ^^^^^^^^^ this section is skipped if the if(has_dup[y] == true) is commented // out and prints undefined if used

    print("\r\nScanned " + recs + " records. Found " + dups + " Duplicate " + dup + "!\r\n\r\n");

    Any help would be appreciated, Thanks






    My teachers always said "You can't make a living looking out a window!", they were wrong, I drive truck :-P

    ---
    þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81
  • From echicken@VERT/ECBBS to Mortifis on Wed Jul 17 16:02:22 2019
    Re: Learning arrays
    By: Mortifis to All on Wed Jul 17 2019 11:09:38

    var has_dup = false;

    This is not an array, so later when you do this:

    has_dup[i] = true;

    you're setting property [i] on a boolean to 'true'. Interestingly this doesn't generate an
    error, but it also doesn't store that property/value.

    Instead of this:

    var has_dup = false;

    you probably want this:

    var has_dup = [];

    Note that you're also declaring 'dups' twice:

    var dups=0;
    var dups;

    So by the time your script gets down to business, 'dups' is undefined and your 'dups++'
    won't work. (Just remove that 'var dups;' line.)

    Your nested for loop could be sped up a little bit:

    for (var n = i + 1; n <= lastuser; n++) {

    You've already dupe-checked all users up to i, and you want to start with users beginning at
    i + 1. This would also remove the need for the 'if(u.number == d.number) continue;' check.

    I could go on with some other suggestions, but I'll stop here for now.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com
    þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com
  • From Mortifis@VERT/ALLEYCAT to echicken on Wed Jul 17 17:43:43 2019
    Re: Learning arrays
    By: Mortifis to All on Wed Jul 17 2019 11:09:38

    var has_dup = false;

    This is not an array, so later when you do this:

    has_dup[i] = true;

    you're setting property [i] on a boolean to 'true'. Interestingly this doesn't generate an
    error, but it also doesn't store that property/value.

    Instead of this:

    var has_dup = false;

    you probably want this:

    var has_dup = [];

    Note that you're also declaring 'dups' twice:

    var dups=0;
    var dups;

    So by the time your script gets down to business, 'dups' is undefined and your 'dups++'
    won't work. (Just remove that 'var dups;' line.)

    Your nested for loop could be sped up a little bit:

    for (var n = i + 1; n <= lastuser; n++) {

    You've already dupe-checked all users up to i, and you want to start with users beginning at
    i + 1. This would also remove the need for the 'if(u.number == d.number) continue;' check.

    yes that sped things up and also forced a deletion of dups = dups/2; :-)


    I could go on with some other suggestions, but I'll stop here for now.

    I am open to suggestions but I think I have a handle on the has_dup Array, thank you :)



    My teachers always said "You can't make a living looking out a window!", they were wrong, I drive truck :-P

    ---
    þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81