My task is to extract an array of numbers from JSON files. I need to handle files that contain only arrays of numbers or one level deeper (referred to as direct arrays). These files may also include other data types such as strings or booleans.
The challenge lies in identifying the array of numbers, as they may be classified as objects when their type is checked.
I must solve this without using any additional libraries. Is there a standard solution available for this issue?
file1.json
[1,2,3,4]
Output:
1,2,3,4
file2.json
{a:'4',b:true,c:[5,6,7]}
Output:
5,6,7
file3.json
{a:[1,'2',3],b:2,c:['1','2','3']}
Output:
[]
The goal is to fulfill a Promise with the sum of numbers extracted and reject it if there are no arrays of numbers or if the JSON files are invalid.