Gotta love some algo work: In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.
Example:
filter_list([1,2,'a','b']) == [1,2]
filter_list([1,'a','b',0,15]) == [1,0,15]
filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
My solution:
const filter_list = l => l.filter(item => typeof item === 'number');
( https://discordapp.com/channels/392832386079129630/704005036732055723/706211068749283368 )
const digital_root = n => {
let count = 0;
n = String(n).split('');
n.forEach(num => {
count += Number(num);
});
console.log(count);
};
( https://discordapp.com/channels/392832386079129630/704005036732055723/706217297320345740 )
i'm sure this can be done with a reduce function in a 1 liner.
const digital_root = n => n.reduce(//something here. a+b possibly.)
or, i could just use a simple for loop. 🤔 i tend to avoid them though haha.
const digital_root = n = {
let count;
for(let i = 0 ; i < n.length-1 ; i++) {
count += n(i);
}
return count;
};
( https://discordapp.com/channels/392832386079129630/704005036732055723/706218230439477299 )