2016-09-30 3 views
0

https://codepen.io/leongaban/pen/EgvBpxWarum ist mein R.flatten (R.map (R.prop Rückkehr und undefiniert Objekt hier? RamdaJS

Wie ich es verstehe, ich bin in meinem comboTags Array gerade vorbei. Die Daten immer in curried ist die rechte Seite eines Ramda Aussage.

ich flatTags bin erwartet ein Array von tag1 und tag2 enthalten

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); 

Antwort

1

Ich glaube, Sie suchen nach pluck auch beachten Sie die Verwendung von compose alternativ pipe verwenden! Dies ermöglicht point-free Funktionen: 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']