Ramda Additions
/////////////////////////////////////////
//// iterate through objects smoothly //
///////////////////////////////////////
// need 'forEach' like list has to iterate through for sideeffects, with access to key, value and full object (could use reduce to implement?)
R.forEachObj(function(key, value, object){ console.log(key, value) })({ yes: 'no', hello: 'goodbye' })
// what if i want to change keys instead of values? ( could use invertObj | mapObjIndexed | invertObj to implement?); what if i wanted to change BOTH in same function?
R.mapObjIndexedKeys(function(key, value, object){ return 'i say' + key })({ yes: 'no', hello: 'goodbye' }) // { 'i say yes': 'no', 'i say hello': 'goodbye' }
/////////////////////
//// truthy logic //
///////////////////
R.isTruthy(true) // true
R.isTruthy('hello') // true
R.isTruthy("") // false
R.all(R.isTruthy)([true, true, true]) // true
///////////////////
//// hasChanged //
/////////////////
var newData = [ { name: 'Tom', age: 4 }, { name: 'Frank', age: 67 } ];
var oldDataNoChange = [ { name: 'Tom', age: 4 }, { name: 'Frank', age: 67 } ];
var oldDataOne = [ { name: 'Tom', age: 34 }, { name: 'Frank', age: 67 } ];
var oldDataTwo = [ { name: 'Tom', age: 4 }, { name: 'Frank', age: 67 }, { name: 'Jim', age: 7 } ];
var hasChanged = function(orderProp, oldData, newData){
var order = R.sort(function(firstPerson, secondPerson){ return R.gt(R.prop(orderProp)(firstPerson), R.prop(orderProp)(secondPerson)) });
var orderedOld = order(oldData);
var orderedNew = order(newData);
if( R.not(R.equals(R.length(orderedOld), R.length(orderedNew))) ){ return true; } // based on length
var pairs = R.zip(orderedOld, orderedNew);
var equalityCheck = R.map(function(pair){ return R.equals(R.head(pair), R.last(pair)) })(pairs);
return R.any(function(check){ return check === false })(equalityCheck); // based on equality
};
hasChanged('name', oldDataTwo, newData) // true