Skip to content

Instantly share code, notes, and snippets.

@meshenka
Forked from anonymous/index.html
Created March 3, 2016 21:03
Show Gist options
  • Save meshenka/712a711ef3e0fdf3c54b to your computer and use it in GitHub Desktop.
Save meshenka/712a711ef3e0fdf3c54b to your computer and use it in GitHub Desktop.
JS Bin test transformation // source https://jsbin.com/bikeci
<!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>
/**
* 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