/**
 * Try to make loopable any kind of javascript primitive
 * @param   {array|number|string|object|Map|Set} collection - hopefully something that we can loop
 * @returns {Array} it will return always an array
 */
export default function looppa(collection) {
    // handle falsy values
    if (!collection) {
        return [];
    }

    // don't touch arrays
    if (Array.isArray(collection)) {
        return collection;
    }

    // handle numbers and strings
    switch (typeof collection) {
        case 'number':
            return Object.keys(Array.from(Array(collection)));
        case 'string':
            return collection.split('');
        default:
            //noop
    }

    // get the object entries
    if (Object.prototype.toString.call(collection) === '[object Object]') {
        return Object
            .keys(collection)
            .reduce(function(acc, key) {
                acc.push([key, collection[key]]);
                return acc;
            }, []);
    }

    // loop Map and Set
    return Array.from(collection);
}

/**
 * Try to make loopable any kind of javascript primitive
 * @param   {array|number|string|object|Map|Set} collection - hopefully something that we can loop
 * @returns {Array} it will return always an array
 */
export default function looppa(collection) {
    // handle falsy values
    if (!collection) {
        return [];
    }

    // handle objects with an 'entries' function
    // such as: Arrays, Maps, Sets, NodeLists...
    if (typeof collection.entries === 'function') {
        return [...collection.entries()];
    }

    // handle numbers and strings
    switch (typeof collection) {
        case 'number':
            return Array.from({ length: collection }, (v, key) => key);
        case 'string':
            return collection.split('');
        default:
            // Default for all other object types, booleans and symbols
            return Object
                .keys(collection)
                .map((key) => {
                    return [key, collection[key]];
                });
    }
}

Normalize return value format for all objects to [key, value] entries
[entries] Normalize return value format for all objects to [key, value] entries

Meaning, an object of the following structure: { a: 1, b: 2 }
Would be returned as [['a', 1], ['b', 2]]

Also, for numbers, return an array of numbers instead of strings.
