【发布时间】:2021-12-14 20:16:26
【问题描述】:
类似于Ramda: How to remove keys in objects with empty values?,但我正在寻找可以递归工作的东西。这样我就可以解决 null !== undefined 的 AJV 和 JSON Schema 的“功能”。
我从这个开始......这是删除空值但不能递归工作
import R from 'ramda';
describe('filter null values', () => {
it('should filter out null values', () => {
const specimen = {
tasks: [
{ id: 'foo', blank: '', zero: 0, nool: null },
{ nool: null },
{ id: '', blank: null, zero: 0, nool: null },
],
useless: { nool: null },
uselessArray: [{ nool: null }],
nool: null,
};
const expectation = {
tasks: [
{ id: 'foo', blank: '', zero: 0 },
{ id: '', zero: 0 },
],
};
const removeNulls = R.reject(R.equals(null));
expect(removeNulls(specimen)).toEqual(expectation);
});
});
【问题讨论】:
标签: javascript jestjs ramda.js