function f(obj) {
for(const key in obj['prop']) {
for(const subkey in obj['prop'][key]) {
obj['prop'][key][subkey] = 'changed'
}
}
for(const key of obj['childs']) {
f(key)
}
}
arr
.reduce({}){|acc, n| acc.update(n[:books])}
.collect{|k, v| { author: k, book: v[:book] }}
.sort_by{|n| n[:author]}
class Hash
def find_all_values_for(key)
result = []
result << self[key]
self.values.each do |hash_value|
values = [hash_value] unless hash_value.is_a? Array
values.each do |value|
result += value.find_all_values_for(key) if value.is_a? Hash
end
end
result.compact
end
end
function flat(obj) {
let arr = [];
Object.entries(obj).forEach(([key, value]) => {
if (value.show) {
arr.push(key);
if (value.child) {
arr = arr.concat(flat(value.child));
}
}
})
return arr;
}
const arr = flat(obj);
const digits = Object
.entries([...`${num}`].reduce((acc, n) => (acc[n] = (acc[n] || 0) + 1, acc), {}))
.reduce((acc, n) => (n[1] > 1 && acc.push(+n[0]), acc), []);
const digits = num
.toString()
.split('')
.reduce((acc, n) => (acc[n]++, acc), Array(10).fill(0))
.map((n, i) => n > 1 && i)
.filter(n => n !== false);
const digits = Array
.from(String(num), Number)
.filter((n, i, a) => i !== a.indexOf(n))
.filter((n, i, a) => i === a.indexOf(n));
const digits = (('' + num)
.match(/\d/g)
.sort()
.join('')
.match(/(\d)\1+/g) || [])
.map(n => n[0] | 0);