You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each item in the second argument array is an array itself, where the first element is a predicate and the second element is a mapper. The function mapEmUp should pick up each item from the supplied array and run it against each item in the second argument. Where a predicate turns out to be true, the corresponding mapper is applied. Note that the search only continues until a match is found. When there is no predicate matching a specific input, return -1;
Kata 來源 https://www.codewars.com/kata/programmed-mapper
Description:
Write a function mapEmUp that conditionally maps an array of inputs according to a set of supplied conditions. The function takes in two arguments:
An array of inputs
An array of key-value pairs of predicates and mappers
For example:
returns
Each item in the second argument array is an array itself, where the first element is a predicate and the second element is a mapper. The function mapEmUp should pick up each item from the supplied array and run it against each item in the second argument. Where a predicate turns out to be true, the corresponding mapper is applied. Note that the search only continues until a match is found. When there is no predicate matching a specific input, return -1;
說明
mapEmUp是一個function, 第一個參數是一個陣列為input的值, 第二個parameter是一個key-value所組成的陣列(predicate, mapper)用來測試輸入的值, 當predicate function條件符合就會由mapper function傳回值
例如這個題目的輸入 [1,2,3] , 就將值傳入測試, 結果傳回 [0,-1,3]
The text was updated successfully, but these errors were encountered: