fix issues reported by Codacy

This commit is contained in:
Henry Szeto
2018-07-13 11:02:11 -07:00
parent fdcf0fb929
commit 57ff7b5474
3 changed files with 18 additions and 2091 deletions

View File

@ -4,8 +4,12 @@ const dig = (obj, target) =>
: Object
.values(obj)
.reduce((acc, val) => {
if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target);
if (acc !== undefined) {
return acc
};
if (typeof val === "object") {
return dig(val, target)
};
}, undefined);
module.exports = dig;
module.exports = dig;

View File

@ -1,5 +1,5 @@
const expect = require('expect');
const dig = require('./dig.js');
const expect = require("expect");
const dig = require("./dig.js");
const data = {
level1:{
@ -11,22 +11,22 @@ const data = {
}
};
test('dig is a Function', () => {
test("dig is a Function", () => {
expect(dig).toBeInstanceOf(Function);
});
test('Dig target success', () => {
expect(dig(data, 'level3')).toEqual('some data');
test("Dig target success", () => {
expect(dig(data, "level3")).toEqual("some data");
});
test('Dig target with falsey value', () => {
expect(dig(data, 'level3f')).toEqual(false);
test("Dig target with falsey value", () => {
expect(dig(data, "level3f")).toEqual(false);
});
test('Dig target with array', () => {
expect(dig(data, 'level3a')).toEqual([1,2,3,4]);
test("Dig target with array", () => {
expect(dig(data, "level3a")).toEqual([1,2,3,4]);
});
test('Unknown target return undefined', () => {
expect(dig(data, 'level4')).toEqual(undefined);
test("Unknown target return undefined", () => {
expect(dig(data, "level4")).toEqual(undefined);
});

File diff suppressed because it is too large Load Diff