Skip to content

Instantly share code, notes, and snippets.

@ShadowCreator250
Last active July 16, 2020 09:45
Show Gist options
  • Save ShadowCreator250/edd172b99174e1b0b1f606d427c42265 to your computer and use it in GitHub Desktop.
Save ShadowCreator250/edd172b99174e1b0b1f606d427c42265 to your computer and use it in GitHub Desktop.
Alan is the best coding bro! He sometimes shares sth on Discord and bc I can still learn from him, I wanted to save some of his stuff here for me to look it up later again. Check him out btw: https://github.com/RecodeExistence

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment