From 2f04ef786dc963e7b21063658728fc2dd475e30f Mon Sep 17 00:00:00 2001 From: Bitbucket Build Date: Thu, 25 Oct 2018 17:40:45 +0300 Subject: [PATCH 1/2] Fix for glitch preventing subelements of indexed array to map correctly. --- src/set-key-value.js | 33 ++++++- test/test.js | 220 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+), 3 deletions(-) diff --git a/src/set-key-value.js b/src/set-key-value.js index 8220295..666271b 100644 --- a/src/set-key-value.js +++ b/src/set-key-value.js @@ -126,16 +126,43 @@ function _setValue(destinationObject, key, keys, fromValue) { if (Array.isArray(fromValue) && _isNextArrayProperty(keys) === false) { for (valueIndex = 0; valueIndex < fromValue.length; valueIndex++) { value = fromValue[valueIndex]; - destinationObject[key][arrayIndex + valueIndex] = _setValue(destinationObject[key][arrayIndex + valueIndex], keys[0], keys.slice(1), value); + const targetIndex = arrayIndex ? parseInt(arrayIndex) : parseInt(valueIndex); + destinationObject[key][targetIndex] = _setValue(destinationObject[key][targetIndex], keys[0], keys.slice(1), value); } } else { - destinationObject[key][arrayIndex] = _setValue(destinationObject[key][arrayIndex], keys[0], keys.slice(1), fromValue); + const findFirstIndexWithoutProp = function(keys, array) { + for(var i=0;i Date: Thu, 25 Oct 2018 17:47:42 +0300 Subject: [PATCH 2/2] Fix to be compliant with the strict mode. --- src/set-key-value.js | 16 ++++++++-------- test/test.js | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/set-key-value.js b/src/set-key-value.js index 666271b..5ffb292 100644 --- a/src/set-key-value.js +++ b/src/set-key-value.js @@ -126,11 +126,11 @@ function _setValue(destinationObject, key, keys, fromValue) { if (Array.isArray(fromValue) && _isNextArrayProperty(keys) === false) { for (valueIndex = 0; valueIndex < fromValue.length; valueIndex++) { value = fromValue[valueIndex]; - const targetIndex = arrayIndex ? parseInt(arrayIndex) : parseInt(valueIndex); + var targetIndex = arrayIndex ? parseInt(arrayIndex) : parseInt(valueIndex); destinationObject[key][targetIndex] = _setValue(destinationObject[key][targetIndex], keys[0], keys.slice(1), value); } } else { - const findFirstIndexWithoutProp = function(keys, array) { + var findFirstIndexWithoutProp = function(keys, array) { for(var i=0;i