[JS Practice] Changing Vowel(替换单词中的元音字母)

Title :

Changing Vowel(替换单词中的元音字母)

Description:

要求实现两个方法,第一个方法在接收到一个包含元音的英文单词后会把元音替换成相应的数字,第二个方法则反过来,会把相应的数字替换成对应的元音单词。
Step 1: Create a function called encode() to replace all the lowercase vowels in a given string with numbers according to the following pattern:

a -> 1

e -> 2

i -> 3

o -> 4

u -> 5

For example, encode(“hello”) would return “h2ll4” There is no need to worry about uppercase vowels in this kata.

Step 2: Now create a function called decode() to turn the numbers back into vowels according to the same pattern shown above.

For example, decode(“h3 th2r2”) would return “hi there”

For the sake of simplicity, you can assume that any numbers passed into the function will correspond to vowels.

Continue reading

[JS Practice] Name Array Capping (第一个字母大写)

Title :

Name Array Capping (第一个字母大写)

Description:

Create a method that accepts an array of names, and returns an array of each name with its first letter capitalized.

完成一个方法,实现当方法在接收到一个以字符串为元素的数组时,方法能否使每个元素的第一个字符大写。

example :

capMe([<span class="string">'jo'</span>, <span class="string">'nelson'</span>, <span class="string">'jurie'</span>]) <span class="comment">// returns ['Jo', 'Nelson', 'Jurie']</span> 
capMe([<span class="string">'KARLY'</span>, <span class="string">'DANIEL'</span>, <span class="string">'KELSEY'</span>]) <span class="comment">// returns ['Karly', 'Daniel', 'Kelsey']</span>

Continue reading

[JS Practice] Remove odd number in an array (去掉数组中的奇数)

Title :

Remove odd number in an array (去掉数组中的奇数)

Description:

Write a small function that returns the values of an array that are not odd.

All values in the array will be integers. Return the good values in the order they are given.

要求实现一个方法,在给方法传入一个只包含数字的数组时,方法可以返回数组中以偶数组成的另外一个数组。

Continue reading

[JS Practice] Calculating sum of values in array with reduce(使用reduce方法计算数组元素之和)

Title :

Calculating sum of values in array with reduce(使用reduce方法计算数组元素之和)

Description:

Make the sum() function return the sum of the values in the passed in array. Your solution must use the reduce() function of the built-in javascript Array object. If you’re not familiar with reduce(), reading over the documentation may help.

function sum(array) {
  // Use array.reduce() to find and return the
  // sum of the values in array.
}

For example:

var someNumbers = [1,2,3,4,5,6,7,8,9,10];

sum(someNumbers); // should return 55

Continue reading