Object spread operator overrides
Babel + JSX
var obj = {a:1, b:2};
var before = {
a: 3,
...obj
};
var after = {
...obj,
a:3
};
const k = 'hello{{wo}}rl{{d{{k:k}}'
const ks = [...k]
console.log('... ks', ks)
const arr = []
ks.forEach((e, i) => {
if (e === "{") {
arr.push({ch: '{', index: i})
} else if (e === '}') {
arr.push({ch: '}', index: i})
}
})
let temp = []
const mainIndex = arr.map((e,i) => {
console.log('e--- ', e)
if (e.ch === "{" && temp.length < 3) {
temp.push(e.index)
if(temp.length === 3) {
return temp
}
} else if (e.ch === "}") {
temp = []
}
/* if (e.ch === "{" && (temp[temp.length - 1] === "" || temp[temp.length - 1] === "{")) {
temp.push({id: e.ch, index: i })
console.log('temp', temp)
} else if (e.ch === "}") {
temp.length = 0
} */
})
console.log('final mainIndex ', mainIndex.filter( Boolean )[0][0])
//console.log('tttt ', arr.map(e => e.ch).toString())
// let arr = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4];
/* let acc = ks.reduce((acc, val) => acc.set(val, 1 + (acc.get(val) || 0)), new Map());
console.log(acc); */
/* ks.forEach((e, i) => {
console.log('e ', e)
if (e === '{') {
console.log('position at {', i)
}
}) */