说明:此函数将接受两个参数。第一个参数应该是一个数组。第二个参数应该是一个数字。您的函数必须执行以下操作:
首先将输入数组(第一个参数)按字母顺序排序。
输入数组排序后,返回一个新数组数组,它是输入数组的前 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' …