mahyuan / Front_end_basics

Anything I can note here about studying
MIT License
1 stars 0 forks source link

splitArray #2

Open mahyuan opened 6 years ago

mahyuan commented 6 years ago
function splitArray (arr, n) {
    if(arr instanceof Array && arr.length) {
        if(arr.length < n) {
            return arr
        } else {
            let a = [...arr]
            a.length = n
            return a
        }
    }
    return []
}