Kata: Prime Factors


Although quite short, this kata is fascinating in the way it shows how “if” statements become “while” statements as the number of test cases increase.  It’s also a wonderful example of how algorithms sometimes become simpler as they become more general.


Easy / 40 minutes


Write a class named “PrimeFactors” that has one method: “generate”. The “generate” method takes an integer argument and returns an array of integers.  That list contains the prime factors in numerical sequence.


Resolve applying TDD, 100% code coverage is possible. When finish, comment on this post with your GitHub repository (or similiar) solution so others can check.


Adapted from http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata