Ad
  • Custom User Avatar

    Linq Select has an override that gives you the index of the current item in the selector (that index is the same number of times you need to repeat). I used Repeat didn't realize there was a string constructor overload that does the same.

    Also totally forgot about string.Join. Much cleaner code than I wrote on my first pass.

  • Custom User Avatar

    decided to diversify the same solutions :D

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    You're returning the last number that's only one digit, read the instructions again:

    Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.

  • Custom User Avatar

    You only have to check if the array is not empty, as easy as that. Fix your code and it'll work.

  • Custom User Avatar

    I love this website because you get to see a lot more of the niche pieces of code, which can be overlooked :)

  • Custom User Avatar

    This is a property which can be pulled through if you want it. I could of named it anything. One the where linq, if you select to name properties (in this case "index"), it will create a property which contains the current interations index. There is another property which can also be pulled through (pretty sure there are 3 properties (1: item of the list, 2: index). Anyway the second name in (n,index) is to reference the index.

    Or as Visual Studio 2017 puts it:
    Filters a sequence of values based on a predicate. Each element’s index is used in the logic of the predicate function.
    Predicate: A function to test each source element for a condition; the second parameter of the function represents the index of the source element.

    Anyway... I know both the Select and Where Linq methods allow you to pull through the index.