闲的没事,总是会去codewars练两把,做几道算法题,学习一下国外的大牛的牛逼之处,这里也算记录分享一下
[TOC]
可以不急着看答案,先去上手做几道,至于答案,如果你有更好更简洁的也请提个issue,共同学习~
#Kata
[6 kyu]Write Number in Expanded Form
Intructions:
You will be given a number and you will need to return it as a string in Expanded Form. For example:


NOTE: All numbers will be whole numbers greater than 0.
Solution:


SampleTests:


[6 kyu]CamelCase Method
Intructions:
Write simple .camelCase method (camel_case function in PHP, CamelCase in C# or camelCase in Java) for strings. All words must have their first letter capitalized without spaces.
For instance:


Don’t forget to rate this kata! Thanks :)
Solution:


SampleTests:


[6 kyu] Reversed Words
Intructions:
Complete the solution so that it reverses all of the words within the string passed in.
Example:


Solution:


SampleTests:


[6 kyu] Replace With Alphabet Position
Intructions:
Welcome.
In this kata you are required to, given a string, replace every letter with its position in the alphabet.
If anything in the text isn’t a letter, ignore it and don’t return it.
a being 1, b being 2, etc.
As an example:


Should return “20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11” as a string.
Solution:


SampleTests:


[6 kyu] Triple trouble
Write a function


which takes in numbers num1 and num2 and returns 1 if there is a straight triple of a number at any place in num1 and also a straight double of the same number in num2.
For example:


If this isn’t the case, return 0
Solution:


SampleTests:


[5 kyu] Where my anagrams at?
Intructions:
What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example:


Write a function that will find all the anagrams of a word from a list. You will be given two inputs a word and an array with words. You should return an array of all the anagrams or an empty array if there are none. For example:


Solution:

Test Driven Development (TDD)


[6 kyu] Find the missing term in an Arithmetic Progression
Intructions:
An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP. Find the missing term.
You have to write the function findMissing(list), list will always be at least 3 numbers. The missing term will never be the first or last one.
Example


PS: This is a sample question of the facebook engineer challenge on interviewstreet. I found it quite fun to solve on paper using math, derive the algo that way. Have fun!
Solution:


Sample Tests:

