Created
April 9, 2022 20:06
-
-
Save BrianJenney/00123ac90634d6ec96c057c0097d3f60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); | |
const flattenArr = (arr) => { | |
const retVal = []; | |
const helper = (val) => { | |
for (let i = 0; i < val.length; i++) { | |
if (Array.isArray(val[i])) { | |
helper(val[i]); | |
} else { | |
retVal.push(val[i]); | |
} | |
} | |
}; | |
helper(arr); | |
return retVal; | |
}; | |
const dataFetcher = async () => { | |
try { | |
const data = await axios.get( | |
'https://jsonplaceholder.typicode.com/users' | |
); | |
return data; | |
} catch (e) { | |
throw new Error({ error: e, message: 'An Error Occurred' }); | |
} | |
}; | |
const createList = (arr, sortFn) => { | |
if (sortFn && arr.length > 1) { | |
return sortFn(arr); | |
} | |
return arr; | |
}; | |
module.exports = { | |
flattenArr, | |
dataFetcher, | |
createList, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment