Maybe somebody knows how to change some data in an object via a function for an array?
For example, I have an object:
var nodes = [
{ topic: "Games", topicscore: 100},
{ topic: "Fun", topicscore: 550},
{ topic: "New York", topicscore: 7799},
{ topic: "Hillary", topicscore: 745},
{ topic: "Politics", topicscore: 512},
{ topic: "Trump", topicscore: 71}
];
And I have a function:
var filterScoreValues = function(array_input){
var a_out = [];
array_input.forEach(function(x){
a_out.push(Math.ceil(x / Math.max.apply(null,array_input) * 10) + 5)
});
return a_out;
};
How I can apply this algorithm to topicscore of my object?
I wrote this, but I want a "pretty" variant, maybe via lodash or similar:
function filterScoreValues(input){
var array = input.map(function (i) {
return i.topicscore;
});
array.forEach(function(x, index){
input[index]['topicscore'] = Math.ceil(x / Math.max.apply(null, array) * 10) + 5;
});
return input;
};
I often used loops on my variant.. :(
Math.max.apply(null,array)once, not on every loop.