Skip to content

Instantly share code, notes, and snippets.

@mactanxin
Created September 26, 2018 16:57
Show Gist options
  • Save mactanxin/ad2721c0941126918b1a61cf5b9b732c to your computer and use it in GitHub Desktop.
Save mactanxin/ad2721c0941126918b1a61cf5b9b732c to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/tugesihala
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var obj = {
"a": "char",
"b": "char",
"c": "char",
"1": "num",
"2": "num",
"3": "num"
}
console.log(2)
function invert(obj){
var result = {};
for(var i in obj){
let result_key = obj[i];
if(!result[result_key]){
result[result_key]= [];
}
result[result_key].push(i)
}
return result;
}
var ss = invert(obj);
console.log(ss)
</script>
<script id="jsbin-source-javascript" type="text/javascript">var obj = {
"a": "char",
"b": "char",
"c": "char",
"1": "num",
"2": "num",
"3": "num"
}
console.log(2)
function invert(obj){
var result = {};
for(var i in obj){
let result_key = obj[i];
if(!result[result_key]){
result[result_key]= [];
}
result[result_key].push(i)
}
return result;
}
var ss = invert(obj);
console.log(ss)</script></body>
</html>
var obj = {
"a": "char",
"b": "char",
"c": "char",
"1": "num",
"2": "num",
"3": "num"
}
console.log(2)
function invert(obj){
var result = {};
for(var i in obj){
let result_key = obj[i];
if(!result[result_key]){
result[result_key]= [];
}
result[result_key].push(i)
}
return result;
}
var ss = invert(obj);
console.log(ss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment