小编Lrn*_*Lru的帖子

为什么我的函数只返回一个元素而不是两个?

说明:此函数将接受两个参数。第一个参数应该是一个数组。第二个参数应该是一个数字。您的函数必须执行以下操作:

首先将输入数组(第一个参数)按字母顺序排序。

输入数组排序后,返回一个新数组数组,它​​是输入数组的前 N ​​个元素,其中 N 是函数的第二个参数的值:

function getFirstAmountSorted(inputArray, numberOfThings) {

    // Step 1 - sort inputArray alphabetically
    let bucket = input.sort();
    let citrus = bucket.slice(0, 1);
    return citrus;

    // Step 2 - create an array which contains the first items of the sorted array -
    // the number of items is provided in the second argument

    // Step 3 - return the new array you created in step 2

}
Run Code Online (Sandbox Code Playgroud)

但是当我用 调用这个函数时(['third, 'second', 'third'], 2),它只在它应该返回时返回第一个'first', 'second' …

javascript arrays sorting function

1
推荐指数
1
解决办法
836
查看次数

标签 统计

arrays ×1

function ×1

javascript ×1

sorting ×1