Skip to content

Instantly share code, notes, and snippets.

@andrewborisov
Last active June 25, 2019 11:22
Show Gist options
  • Save andrewborisov/4abe3866e0db49348ccd2d5caf108e7c to your computer and use it in GitHub Desktop.
Save andrewborisov/4abe3866e0db49348ccd2d5caf108e7c to your computer and use it in GitHub Desktop.
const findRecursivelyValuesQuantity = (object) => {
if (keys(object).lenght === 0) {
return 0;
}
const objKeys = keys(object);
const result = objKeys.map((i) => {
const currentValue = object[i];
if (isFunction(currentValue) || (isArray(currentValue) && !isEmpty(currentValue)) || isNumber(currentValue)
|| (!isObject(currentValue) && !isEmpty(currentValue))) {
return 1;
}
return findRecursivelyValuesQuantity(currentValue);
});
return result.reduce((acc, currentValue) => acc + currentValue);
}
describe('findRecursivelyValuesQuantity', () => {
it('', () => {
const mockObject = {};
expect(findRecursivelyValuesQuantity(mockObject)).toBe(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment