From a5c1421c6b895566aff8f48e43d010caf50b6abe Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 14 Jan 2016 19:36:04 -0800 Subject: [PATCH] Ensure `_.fromPairs` can consume results of `_.toPairs`. [closes #1790] --- lodash.js | 2 +- test/test.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lodash.js b/lodash.js index f3429efe4..15b500338 100644 --- a/lodash.js +++ b/lodash.js @@ -5751,7 +5751,7 @@ while (++index < length) { var pair = pairs[index]; - baseSet(result, pair[0], pair[1]); + result[pair[0]] = pair[1]; } return result; } diff --git a/test/test.js b/test/test.js index c97b0c551..3459acce4 100644 --- a/test/test.js +++ b/test/test.js @@ -6326,13 +6326,13 @@ QUnit.module('lodash.fromPairs'); (function() { - var object = { 'barney': 36, 'fred': 40 }, - array = [['barney', 36], ['fred', 40]]; - QUnit.test('should accept a two dimensional array', function(assert) { assert.expect(1); - var actual = _.fromPairs(array); + var array = [['a', 1], ['b', 2]], + object = { 'a': 1, 'b': 2 }, + actual = _.fromPairs(array); + assert.deepEqual(actual, object); }); @@ -6350,16 +6350,17 @@ assert.deepEqual(actual, expected); }); - QUnit.test('should support deep paths', function(assert) { + QUnit.test('should not support deep paths', function(assert) { assert.expect(1); var actual = _.fromPairs([['a.b.c', 1]]); - assert.deepEqual(actual, { 'a': { 'b': { 'c': 1 } } }); + assert.deepEqual(actual, { 'a.b.c': 1 }); }); QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) { assert.expect(1); + var object = { 'a.b.c': 1 }; assert.deepEqual(_.fromPairs(_.toPairs(object)), object); });