This lesson we learn a very useful method of array: filter(). The filter() method creates a new array with all elements that pass the test implemented by the provided function. For more information, please refer to: Array.prototype.filter()
filter() always accept a function as parameter, the function always return boolean value true or false. filter() returns a new array that contains only the elements that meet the conditions(The elements as a parameters of the function, return true value).
Coding in function countGrade. function accept 1 parameters scores, it's a number array. Your task is to count the grade distribution of the scores, to return an object like this:
題目
This lesson we learn a very useful method of array: filter(). The filter() method creates a new array with all elements that pass the test implemented by the provided function. For more information, please refer to: Array.prototype.filter()
filter() always accept a function as parameter, the function always return boolean value true or false. filter() returns a new array that contains only the elements that meet the conditions(The elements as a parameters of the function, return true value).
Coding in function countGrade. function accept 1 parameters scores, it's a number array. Your task is to count the grade distribution of the scores, to return an object like this:
http://www.codewars.com/kata/573023c81add650b84000429/train/javascript
翻譯:
這一課,我們會學到非常有用的陣列方法: filter(). filter() 函式,會回傳一個陣列,當元素能夠通過我們提供的一個方法的檢查。想知道更多,請參考Array.prototype.filter() filter() 永遠只接受一個函式的參數,這個函式必須要回傳布林值 true或 false. filter() 會回傳一個陣列,這個陣列只容納通過函式測試後回傳true的元素。 請見立一個函式叫做 countGrade,函式能夠接受一個成績的陣列參數,這個參數會是一個數字陣列,你的工作就是去計算成績的結果。
by Raymond Tong