Updated flattenObject tests

This commit is contained in:
Angelos Chalaris
2018-02-07 11:36:01 +02:00
parent 12238b8e78
commit d14b19406e
5 changed files with 9 additions and 13 deletions

View File

@ -1,11 +1,7 @@
const flattenObject = (obj, prefix = '') =>
Object.keys(obj).reduce((acc, k) => {
const pre = prefix.length ? (prefix + '.') : '';
if (typeof obj[k] === 'object')
Object.assign(
acc,
flattenObject(obj[k], pre + k)
);
const pre = prefix.length ? prefix + '.' : '';
if (typeof obj[k] === 'object') Object.assign(acc, flattenObject(obj[k], pre + k));
else acc[pre + k] = obj[k];
return acc;
}, {});