"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("./util");
function unique(input, key) {
    var tElements = {};
    var tElementType = typeof input[0];
    input.forEach(function (element) {
        if (key) {
            if (tElements[element[key]] !== undefined) {
                return;
            }
            tElements[element[key]] = element;
        }
        else {
            if (tElements[element] !== undefined) {
                return;
            }
            tElements[element] = true;
        }
    });
    if (key !== undefined) {
        return Object.getOwnPropertyNames(tElements).map(function (prop) { return tElements[prop]; });
    }
    var tReturn = Object.getOwnPropertyNames(tElements);
    if (tElementType === "number") {
        return tReturn.map(function (prop) {
            return prop.indexOf(".") > -1 ? parseFloat(prop) : parseInt(prop);
        });
    }
    return tReturn;
}
exports.unique = unique;
function filterMap(arr, f) {
    var results = [];
    arr.forEach(function (item, index, arr) {
        var mapped = f(item, index, arr);
        if (mapped !== false) {
            results.push(mapped);
        }
    });
    return results;
}
exports.filterMap = filterMap;
exports.create = function (length, factory) {
    var tResult = [];
    for (var index = 0; index < length; index++) {
        tResult.push(factory ? factory(index) : index);
    }
    return tResult;
};
exports.filterNullsy = function (items) {
    var result = [];
    for (var index = 0; index < items.length; index++) {
        var item = items[index];
        if (!util_1.isNullOrUndefined(item)) {
            result.push(item);
        }
    }
    return result;
};
