From cc2cd5792fde0faab533663acb762a4b71dee088 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Fri, 26 Jul 2019 20:57:15 -0400 Subject: [PATCH] Simplify --- src/utils/index.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index 9b96929ad..1040f92b6 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -27,21 +27,17 @@ exports.isPlainObject = function isPlainObject(obj) { }; exports.normalizeQuery = function normalizeQuery(query) { - // foreach key, get the last element if it's an array - return Object.keys(query).reduce((q, param) => { - q[param] = [].concat(query[param]).pop(); - - return q; - }, {}); + // foreach key, ensure that the value is an array + return fromEntries( + entries(query).map(([key, value]) => [key, [].concat(value).pop()]), + ); }; exports.normalizeMultiValueQuery = function normalizeMultiValueQuery(query) { // foreach key, ensure that the value is an array - return Object.keys(query).reduce((q, param) => { - q[param] = [].concat(query[param]); - - return q; - }, {}); + return fromEntries( + entries(query).map(([key, value]) => [key, [].concat(value)]), + ); }; exports.capitalizeKeys = function capitalizeKeys(o) {