I am looking to modify properties for an object in ramda.js without using lenses.
Given the data provided, I need to:
If objects in array properties in a
and b
do not have the property "animationTimingFunction", then add the property key "easing" with a value of ease
If the objects do have the property "animationTimingFunction", rename this property to "easing" while keeping the original value.
Input data:
let data = {
"a": [{
"opacity": "1",
"offset": "0"
}, {
"opacity": "0",
"offset": "0.25",
"animationTimingFunction": "linear"
}, {
"opacity": "1",
"offset": "0.5"
},
"b": [{
"transform": "scale3d(1, 1, 1)",
"offset": "0"
}, {
"transform": "scale3d(1.05, 1.05, 1.05)",
"offset": "0.5"
}, {
"transform": "scale3d(1, 1, 1)",
"offset": "1"
}]
};
Output should be:
let data = {
"a": [{
"opacity": "1",
"offset": "0",
"easing": "ease"
}, {
"opacity": "0",
"offset": "0.25",
"easing": "linear"
}, {
"opacity": "1",
"offset": "0.5",
"easing": "ease"
},
"b": [{
"transform": "scale3d(1, 1, 1)",
"offset": "0",
"easing": "ease"
}, {
"transform": "scale3d(1.05, 1.05, 1.05)",
"offset": "0.5",
"easing": "ease"
}, {
"transform": "scale3d(1, 1, 1)",
"offset": "1",
"easing": "ease"
}]
};
I have attempted a solution but I'm missing the condition part:
let convertEasing = (data) =>{
let convert = data => R.assoc('easing', 'linear');
let result = R.map(R.map(convert(data)), data)
return result;
};