From e24d04dd5788ffb499d0c7d5bc613b346571ed01 Mon Sep 17 00:00:00 2001 From: Joe Morgan Date: Fri, 2 Feb 2018 10:57:48 -0600 Subject: [PATCH 1/4] push up stuff for PR --- src/objectUtils.js | 20 ++++++++++++++++++++ src/objectUtils.spec.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/objectUtils.js b/src/objectUtils.js index 755f23d..c04a0fc 100644 --- a/src/objectUtils.js +++ b/src/objectUtils.js @@ -24,3 +24,23 @@ export function assignDeep(target, source) { } return output; } + +function alphabetizeKeys(target, blacklist = []) +{ + const usableKeys = []; + let keys = Object.keys(target); + for(var i = 0; i < keys.length; i++) { + if(blacklist.indexOf(keys[i]) > -1) { + continue; + } + usableKeys.push(keys[i]); + }; + usableKeys.sort(); + const updated = {}; + for(var i=0; i < usableKeys.length; i++) { + updated[usableKeys[i]] = target[usableKeys[i]]; + } + return updated; +} + +export { alphabetizeKeys } diff --git a/src/objectUtils.spec.js b/src/objectUtils.spec.js index 78927aa..fee980f 100644 --- a/src/objectUtils.spec.js +++ b/src/objectUtils.spec.js @@ -1,5 +1,5 @@ import expect from 'expect'; -import {ensureArray} from './objectUtils'; +import { ensureArray, alphabetizeKeys } from './objectUtils'; describe('ensureArray', () => { it('should put object in array', () => { @@ -16,3 +16,30 @@ describe('ensureArray', () => { expect(ensureArray([obj])).toEqual([obj]); }); }); + +// describe('alphabetizeKeys', () => { +// it('should alphabetize keys', () => { +// const original = { +// name: 'joe', +// age: 35 +// } +// const expected = { +// age: 35, +// name: 'joe' +// } +// expect(alphabetizeKeys(original)).toEqual(expected); +// }) +// +// it('should remove blacklist', () => { +// const original = { +// name: 'joe', +// ugliness: 'high', +// age: 35 +// } +// const expected = { +// age: 35, +// name: 'joe' +// } +// expect(alphabetizeKeys(original, 'ugliness')).toEqual(expected); +// }) +// }) From 3f0decc37e07e250fc39896a8f42ee9ac7e85f11 Mon Sep 17 00:00:00 2001 From: Joe Morgan Date: Fri, 2 Feb 2018 15:49:00 -0600 Subject: [PATCH 2/4] linting --- .gitignore | 1 + src/objectUtils.js | 15 +++++++-------- src/objectUtils.spec.js | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index c2658d7..1ca9571 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +npm-debug.log diff --git a/src/objectUtils.js b/src/objectUtils.js index c04a0fc..49012ae 100644 --- a/src/objectUtils.js +++ b/src/objectUtils.js @@ -25,22 +25,21 @@ export function assignDeep(target, source) { return output; } -function alphabetizeKeys(target, blacklist = []) -{ +function alphabetizeKeys(target, blacklist = []) { const usableKeys = []; - let keys = Object.keys(target); - for(var i = 0; i < keys.length; i++) { - if(blacklist.indexOf(keys[i]) > -1) { + const keys = Object.keys(target); + for (var i = 0; i < keys.length; i++) { + if (blacklist.indexOf(keys[i]) > -1) { continue; } usableKeys.push(keys[i]); - }; + } usableKeys.sort(); const updated = {}; - for(var i=0; i < usableKeys.length; i++) { + for (var i = 0; i < usableKeys.length; i++) { updated[usableKeys[i]] = target[usableKeys[i]]; } return updated; } -export { alphabetizeKeys } +export {alphabetizeKeys}; diff --git a/src/objectUtils.spec.js b/src/objectUtils.spec.js index fee980f..c6e3b1c 100644 --- a/src/objectUtils.spec.js +++ b/src/objectUtils.spec.js @@ -1,5 +1,5 @@ import expect from 'expect'; -import { ensureArray, alphabetizeKeys } from './objectUtils'; +import {ensureArray, alphabetizeKeys} from './objectUtils'; describe('ensureArray', () => { it('should put object in array', () => { @@ -19,7 +19,7 @@ describe('ensureArray', () => { // describe('alphabetizeKeys', () => { // it('should alphabetize keys', () => { -// const original = { +// const original = { // name: 'joe', // age: 35 // } @@ -29,9 +29,9 @@ describe('ensureArray', () => { // } // expect(alphabetizeKeys(original)).toEqual(expected); // }) -// +// // it('should remove blacklist', () => { -// const original = { +// const original = { // name: 'joe', // ugliness: 'high', // age: 35 From 8105e5bdee9b5cd02bc994f7c45bbb8ef11b240a Mon Sep 17 00:00:00 2001 From: Joe Morgan Date: Fri, 2 Feb 2018 15:50:26 -0600 Subject: [PATCH 3/4] remove var statements --- src/objectUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/objectUtils.js b/src/objectUtils.js index 49012ae..ae1433b 100644 --- a/src/objectUtils.js +++ b/src/objectUtils.js @@ -28,7 +28,7 @@ export function assignDeep(target, source) { function alphabetizeKeys(target, blacklist = []) { const usableKeys = []; const keys = Object.keys(target); - for (var i = 0; i < keys.length; i++) { + for (let i = 0; i < keys.length; i++) { if (blacklist.indexOf(keys[i]) > -1) { continue; } @@ -36,7 +36,7 @@ function alphabetizeKeys(target, blacklist = []) { } usableKeys.sort(); const updated = {}; - for (var i = 0; i < usableKeys.length; i++) { + for (let i = 0; i < usableKeys.length; i++) { updated[usableKeys[i]] = target[usableKeys[i]]; } return updated; From 0b76f228afee8694c3c4acca76036ebf6d667425 Mon Sep 17 00:00:00 2001 From: Joe Morgan Date: Fri, 2 Feb 2018 15:55:37 -0600 Subject: [PATCH 4/4] incorporate feedback --- src/objectUtils.js | 9 ++----- src/objectUtils.spec.js | 52 ++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/objectUtils.js b/src/objectUtils.js index ae1433b..601b181 100644 --- a/src/objectUtils.js +++ b/src/objectUtils.js @@ -26,14 +26,9 @@ export function assignDeep(target, source) { } function alphabetizeKeys(target, blacklist = []) { - const usableKeys = []; const keys = Object.keys(target); - for (let i = 0; i < keys.length; i++) { - if (blacklist.indexOf(keys[i]) > -1) { - continue; - } - usableKeys.push(keys[i]); - } + + const usableKeys = keys.filter(key => !blacklist.includes(key)); usableKeys.sort(); const updated = {}; for (let i = 0; i < usableKeys.length; i++) { diff --git a/src/objectUtils.spec.js b/src/objectUtils.spec.js index c6e3b1c..5e7269e 100644 --- a/src/objectUtils.spec.js +++ b/src/objectUtils.spec.js @@ -17,29 +17,29 @@ describe('ensureArray', () => { }); }); -// describe('alphabetizeKeys', () => { -// it('should alphabetize keys', () => { -// const original = { -// name: 'joe', -// age: 35 -// } -// const expected = { -// age: 35, -// name: 'joe' -// } -// expect(alphabetizeKeys(original)).toEqual(expected); -// }) -// -// it('should remove blacklist', () => { -// const original = { -// name: 'joe', -// ugliness: 'high', -// age: 35 -// } -// const expected = { -// age: 35, -// name: 'joe' -// } -// expect(alphabetizeKeys(original, 'ugliness')).toEqual(expected); -// }) -// }) + describe('alphabetizeKeys', () => { + it('should alphabetize keys', () => { + const original = { + name: 'joe', + age: 35 + } + const expected = { + age: 35, + name: 'joe' + } + expect(alphabetizeKeys(original)).toEqual(expected); + }) + + it('should remove blacklist', () => { + const original = { + name: 'joe', + ugliness: 'high', + age: 35 + } + const expected = { + age: 35, + name: 'joe' + } + expect(alphabetizeKeys(original, 'ugliness')).toEqual(expected); + }) + })