Domino Code Fragment

Code Name*
List-processing functions
Date*
07/08/2000
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.
Description*
The list-processing functions of the @formula language provide some of the strongest processing capabilities of any built in feature of Notes. Translating them to JavaScript is fairly straightforward. List in JavaScript are implemented as arrays, but you use them in almost the same way you do the @formula language. Perhaps the most obvious use of these functions on a Web page is in string parsing, but your imagination and necessity may suggest many more. Here are the JavaScript versions of some list processing functions:
Type*
JavaScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

function implode(arr, separator) {
        fixedImplode = "";
        seperator = new String(separator);
        if (separator == "undefined")  { separator = " "; }
        for (x = 0; x < arr.length; x++)  { fixedImplode += (separator + String(arr[x] )); }
        fixedImplode = fixedImplode.substring(separator.length, fixedImplode.length);
        return fixedImplode;
}

function explode(inputstring, separators, includeEmpties) {
        inputstring = new String(inputstring);
        separators = new String(separators);
        if (separators == "undefined")  { separators = " :;"; }
        fixedExplode = new Array(1);
        currentElement = "";
        count = 0;
        for(x = 0; x < inputstring.length; x++) {
                char = inputstring.charAt(x);
                if (separators.indexOf(char) != -1) {
                        If (((includeEmpties <= 0) || (includeEmpties == false)) &&
                           (currentElement == "")) {}
                        else { fixedExplode[count] = currentElement;
                                 count++;
                                 currentElement = ""; } }
                else { currentElement += char; }
        }
        if ((!(includeEmpties <=0) && (includeEmpties != false)) || (currentElement != "")) {
                fixedExplode[count] = currentElement; }
        return fixedExplode;
}

function subset(list, numberOfElements) {
        numElements = Math.abs(numberOfElements);
        count = 0;
        if (numElements > list.length)  { numElements = list.length; }
        if (numElements == 0) { fixedSubset = new Array(0); }
        else { fixedSubset = new Array(numElements);
                if (numberOfElements < 0) { start = list.length - numElements; }
                else { start = 0; }
                for (x = start; x < (start + numElements); x++) {
                        fixedSubset[count] = list[x];
                        count++; }
        }
        return fixedSubset;
}

function unique(inputUnique) {
        checkArray = new Array(inputUnique.length);
        matches = 0;
        for (x = 0; x < inputUnique.length; x++) {
                if (checkArray[x] != 1) {
                        for (y = x + 1; y < inputUnique.length; y++) {
                                if (inputUnique[x] == inputUnique[y]) {
                                        foundMatch = true;
                                        if (checkArray[y] != 1) {
                                                matchess++;
                                                checkArray[y] = 1;
                                        }
                                }
                        }
                }
        }
        returnArray = new Array(inputUnique.length - matches);
        returnArrayPos = 0;
        for (x = 0; x < checkArray.length; x++) {
                if (checkArray[x] != 1) {
                   returnArray[returnArrayPos] = inputUnique[x];
                   returnArrayPos++;
                }
        }
        return returnArray;
}