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

Title :

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


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 (第一个字母大写)


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 (去掉数组中的奇数)


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方法计算数组元素之和)


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