const nextBigger = arr => {
const num = arr.join('');
const max = arr.sort((a, b) => b - a).join('');
const tpl = ''.padStart(arr.length, '-')
const check = str => {
arr.forEach(v => str = str.replace(v, '-'))
return str === tpl
}
if (max === num) return -1;
let n = +num;
while (true) {
n += 9
if (check(n.toString())) return n
}
}
const obj = {
something: {
something1: 'value',
something2: 'value1',
something3: {
something4: 'value2'
}
}
}
const getKeys = obj => {
const res = []
for (const key in obj) {
res.push(key)
obj[key] && Object.getPrototypeOf(obj[key]) === Object.prototype && res.push(...getKeys(obj[key]))
}
return res
}
console.log(getKeys(obj))
//[ 'something', 'something1', 'something2', 'something3', 'something4' ]
const str = `{"response": {"one": {"count": "2","total": "13700","rest": "31500","down": "2500"},"two": {"count": "1","total": "25000","rest": "50000","down": ""},"three": {"count": "2","total": "50000","rest": "5000","down": ""}}}`
const obj = JSON.parse(str);
let sum = 0;
for (let key in obj.response) {
sum += +obj.response[key].count;
}
console.log(sum); //5