我對此練習不太瞭解。在Javascript陣列的前半部分查找元素
arr = [1, 2, 3];
arr.indexOf(2); // 1
arr.indexOf(4); // -1 since it doesn't exist.
// Write a function to determine if an element
// is in the first half of an array.
// If an element has an odd length, round up
// when counting the first half of an array.
// For example, 1 and 2 are in the first half
// arr.
function inFirstHalf(inputArray, element) {
}
我不明白,數組的前半部分是什麼意思?
我想這意味着,如果*的indexOf *返回一個值小於*改編的一半。如果長度爲奇數(這意味着實際上你必須向下舍入,因爲數組索引從0開始)。 – RobG
@RobG你讓我的一天! – ricardoorellana
謝謝@RobG,我正在參加這個課程https://www.codecademy.com/courses/javascript-intro/8/4,我被困在那個練習中。 – ricardoorellana