SOURCE

function map(arr, callback) {
    if (!Array.isArray(arr) || !arr.length || typeof callback !== 'function') {
        return []
    }
    let result = []

    for (let i = 0; i < arr.length; i++) {
        result.push(callback(arr[i], i, arr))
    }

    return result
}

function fn(value, idx, arr) {
    return value * 2
}


var arr = [...Array(10).keys()]

console.log(map(arr, fn))
console 命令行工具 X clear

                    
>
console