[JS Practice] Valid The Coupon Code

Title :

Valid The Coupon Code

Description:

Your online store likes to give out coupons for special occasions. Some customers try to cheat the system by entering invalid codes or using expired coupons.

Your mission:
Write a function called checkCoupon to verify that a coupon is valid and not expired. If the coupon is good, return true. Otherwise, return false.

A coupon expires at the END of the expiration date. All dates will be passed in as strings in this format: “June 15, 2014”

Continue reading

[JS Practice] Find majuscule letters

Title :

Find majuscule letters

Description:

Instructions

Write a function capitals that takes a single string (word) as argument. The functions must return an ordered list containing the indexes of all capital letters in the string.

Example

Test.assertSimilar( capitals('CodEWaRs'), [0,3,4,6] );

Continue reading

[JS Practice] Difference of 2 (相差2)

Title :

Difference of 2

Description:

The objective is to obtain the various sets of integers that have a difference of 2 from a given array of integers. The result array should be sorted in ascending order of values.

So for example for the array of integers

[1,2,3,4] should return [[1,3],[2,4]]

[4,1,2,3] should also return [[1,3],[2,4]]

[1,23,3,4,7] should return [[1,3]]

Assume there are no duplicate integers in the array. The order of the integers in the input array should not matter.

Continue reading

[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

[JS Practice] Summing a number’s digits(对各个位数上的数字求和)

Title :

Summing a number’s digits(对各个位数上的数字求和)

Description:

Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number’s decimal digits. For example:

  sumDigits(10); // Returns 1
  sumDigits(99); // Returns 18
  sumDigits(-32); // Returns 5

Let’s assume that all numbers in the input will be integer values.

Continue reading