Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 476 Bytes

literate.org

File metadata and controls

25 lines (22 loc) · 476 Bytes

Remove duplicate strings from array

JavaScript

function rmdupes (array) {
    var obj = {};
    var i = 0;
    array.forEach(function (val, idx) {
        obj[val] = true;
    });
    var uniqs = Object.keys(obj);
    uniqs.forEach(function (val, idx) {
        array[i] = val;
        i++;
    });
    array.length = i;
    return array;
}

Common Lisp

(setf array (remove-duplicates array :test (function string=)))