Create parser for getFruits API response
This commit is contained in:
15
src/utils/parser.js
Normal file
15
src/utils/parser.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export default (data, keyToFind) => {
|
||||
const result = [];
|
||||
JSON.stringify(data, (_, nestedValue) => {
|
||||
if (nestedValue && nestedValue[keyToFind]) {
|
||||
result.push(nestedValue);
|
||||
}
|
||||
return nestedValue;
|
||||
});
|
||||
|
||||
result.sort((a, b) => {
|
||||
return a.id - b.id;
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
Reference in New Issue
Block a user