-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
leetcode中的一些题解 #18
Labels
Comments
排序动画演示https://visualgo.net/zh/sorting |
对象扁平var entryObj = {
a: {
b: {
c: {
dd: 'abcdd'
}
},
d: {
xx: 'adxx'
},
e: 'ae'
}
}
// 要求转换成如下对象
var outputObj = {
'a.b.c.dd': 'abcdd',
'a.d.xx': 'adxx',
'a.e': 'ae'
} function isObject(ob) {
return Object.prototype.toString.call(ob) === '[object Object]';
}
function flat(entryObj) {
let result = {};
fn(entryObj);
return result;
function fn(obj, tmp='') {
for (let key in obj) {
if (isObject(obj[key])) {
fn(obj[key], tmp + key);
} else {
result[tmp + key] = obj[key];
}
}
}
}
console.log(flat(entryObj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
两数求和
解题:
The text was updated successfully, but these errors were encountered: