2016-09-30 1 views
0

https://codepen.io/leongaban/pen/EgvBpxはなぜR.flatten(R.map(R.propはここに戻って、未定義のオブジェクトです?私はそれを理解したようRamdaJS

が、私はちょうどに私のcomboTags配列を渡している。データは常ににカリー化されましたRAMDA文の右側。

私はtag1tag2

enter image description here

const comboTags = [ 
    { 
    tags: [ 
     { 
     name: 'tag1' 
     } 
    ], 
    person: { 
     name: 'Jerry' 
    } 
    }, 
    { 
    tags: [ 
     { 
     name: 'tag2' 
     } 
    ], 
    person: { 
     name: 'Laura' 
    } 
    } 
]; 

const flattenTags = container => R.flatten(R.map(R.prop('tags'))); 

let flatTags = flattenTags(comboTags); 
console.log('flatTags',flatTags); 
の配列を含むように flatTagsを期待してい210

答えて

1

私はあなたがpluckを探していると信じていますcomposeの代わりにpipeを使用してメモの使用も注意してください!これにより、ポイントフリー機能が実現します。Try It Out

const comboTags = [ 
    { 
    tags: [ 
     { 
     name: 'tag1' 
     } 
    ], 
    person: { 
     name: 'Jerry' 
    } 
    }, 
    { 
    tags: [ 
     { 
     name: 'tag2' 
     } 
    ], 
    person: { 
     name: 'Laura' 
    } 
    } 
]; 

const getTagNames = R.compose(R.pluck('name'), R.flatten, R.pluck('tags')) 

getTagNames(comboTags) // ['tag1', 'tag2'] 
関連する問題