• Learning arrays

    From Mortifis@VERT/ALLEYCAT to All on Wed Jul 17 11: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 11:02:22 2019
    Re: Learning arraysã By: Mortifis to All on Wed Jul 17 2019 11:09:38ãã Mo> var has_dup = false;ããThis is not an array, so later when you do this:ãã Mo> 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:ãã Mo> var dups=0;ã Mo> 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 12:43:43 2019
    Re: Learning arraysã > By: Mortifis to All on Wed Jul 17 2019 11:09:38ãã > Mo> var has_dup = false;ãã > This is not an array, so later when you do this:ãã > Mo> 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:ãã > Mo> var dups=0;ã > Mo> 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ã