I have a small problem, I have an array of children, I parse it, I get data from it and reformat it and push it into another array subMenuContent, it is working fine, but I need to clean my code a little bit better, I am using ramda as a library to simplify things for me.
Here is what I was doing before, simple javascript.
let subMenuContent = [];
for (let counter = 0; counter < children.length; counter++) {
let parent = children[counter].props.item.id;
let childs = children[counter].props.item.childrens;
for (let i = 0; i < childs.length; i++) {
let child = {
content: childs[i],
class: 'cdiscountLinks cdiscountChip-' + childs[i].id + '-' + parent,
};
subMenuContent.push(child);
}
}
What I am trying to do now is :
const subMenuContents = map(function(item){
let parent = item.props.item.id;
let childs = item.props.item.childrens;
const itemChilds = map(function(child){
let childItem = {
content: child,
class: 'cdiscountLinks cdiscountChip-' + child.id + '-' + parent,
}
return childItem;
}, childs)
return itemChilds;
},children)
EDIT : Now I used this
const subMenuContents = pipe(
map(function(item) {
let parent = item.props.item.id;
let childs = item.props.item.childrens;
const itemChilds = map(function(child) {
let childItem = {
content: child,
class: 'cdiscountLinks cdiscountChip-' + child.id + '-' + parent,
};
return childItem;
}, childs);
return itemChilds;
}, children),
flatten,
)(subMenuContents);
But I get an error :
f.apply is not a function
What am I doing wrong ? Any help would be much appreciated.