js array auto expand All In One
js array auto expand All In One
const arr = [
{
x: 1,
y: 1,
value:1,
},
{
x: 2,
y: 2,
value: 2,
},
{
x: 3,
y: 3,
value: 3,
}
];
const autoExpand = (arr = []) => {
let result = [];
for (const obj of arr) {
const len = obj.value;
const temp = [...''.padStart(len, ' ')].map((item, i) => ({
x: obj.x,
y: obj.y,
value: len,
}));
// console.log('temp =', temp);
result = result.concat(temp);
}
return result;
};
const test = autoExpand(arr);
console.log('arr', arr);
console.log('test', test);
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15734740.html
未经授权禁止转载,违者必究!