Develop a simple application for sorting and selecting data according to predefined criteria
rules The application must be able to work with a list of arbitrary JSON object
structures, select objects corresponding to keys with corresponding values, and also
sort objects by value using the natural sort order.
I tried different ways like filter(), map(), sort, and many others…
I am a full noob….
example
{"data":[ {"name": "Peter", "email": "[email protected]"},
{"name": "Peter", "email": "[email protected]"},
{"name": "Marge", "email": "[email protected]"}]}
income values:
{"condition": {"include": [{"name": "Peter"}], "sortBy": ["email"]}}// returns only with name peter
and
"condition": {"exclude": [{"name":"Marge"}], "sort_by": ["email"]}} // returns other
Actually, I want to understand what and how so if you can explain it will be great. thanks a lot)
`const data = [
{"name": "John", "email": "[email protected]"},
{"name": "John", "email": "[email protected]"},
{"name": "Jane", "email": "[email protected]"},
{"name": "Margaret", "email": "[email protected]"} ];
function fullSort (arr, sort_by){
const propComparator = (sort_by) =>
(a, b) => a[sort_by] === b[sort_by] ? 0 : a[sort_by] < b[sort_by] ? -1 : 1; /// working
console.log("by parametr", data);
function arrayRemove(arr, sort_by) {
return data.filter(function(ele){ ///working
return ele.name != sort_by;
});
}
console.log(arrayRemove(arr, sort_by))
data.sort(propComparator("sort_by"))
}
return fullSort(data, "John");`