function objToString(val, tabSize = 2, depth = 0, noIndent = false) {
const indent = ' '.repeat(tabSize * depth);
return (noIndent ? '' : indent) + (
val instanceof Array
? `[\n${val.map(n => objToString(n, tabSize, depth + 1)).join(',\n')}\n${indent}]`
: val instanceof Object
? `{\n${Object
.entries(val)
.map(n => n.map((m, i) => objToString(m, tabSize, depth + 1, i)).join(': '))
.join(',\n')}\n${indent}}`
: typeof val === 'string'
? `"${val}"`
: val
);
}
console.log(objToString({
numbers: [ 69, 187, 666 ],
strings: [ 'hello, world!!', 'fuck the world', 'fuck everything' ],
falsy_values: [ 0, '', NaN, false, null, undefined ],
object: { xxx: true, yyy: Infinity, zzz: { '!&$': [ [ [ -1 ] ] ] } }
}));
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 getRandomNumber = (min, max) => {
return Math.floor(Math.random() * (max - min)) + min;
};
const startNum = getRandomNumber(1, 100);
const progrStep = getRandomNumber(1, 10);
const progrCount = 10;
const str = [];
for (let i = startNum; i < startNum + progrCount * progrStep; i += progrStep) {
str.push(i);
}
str[getRandomNumber(0, 9)] = '..';
console.log(str.join(' '));