-
-
Save meshenka/712a711ef3e0fdf3c54b to your computer and use it in GitHub Desktop.
JS Bin test transformation // source https://jsbin.com/bikeci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="test transformation"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/** | |
* convert path string to nested json object | |
* es6 | |
*/ | |
'use strict'; | |
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | |
var str = 'a.b.xc.d'; | |
var value = 7; | |
var obj = str.split('.').reduceRight(function (acc, key) { | |
return _defineProperty({}, key, acc); | |
}, value); | |
console.log(obj); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/** | |
* convert path string to nested json object | |
* es6 | |
*/ | |
const str='a.b.xc.d'; | |
const value = 7; | |
const obj = str.split('.').reduceRight((acc, key) => ({ [key]: acc }), value); | |
console.log(obj);</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* convert path string to nested json object | |
* es6 | |
*/ | |
'use strict'; | |
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | |
var str = 'a.b.xc.d'; | |
var value = 7; | |
var obj = str.split('.').reduceRight(function (acc, key) { | |
return _defineProperty({}, key, acc); | |
}, value); | |
console.log(obj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment