[JS Practice] Adjacent pairs in a string

Title :

Adjacent pairs in a string


Supplied with a single string, return the number of all adjacent pairs in that string.

The words within the string are separated by whitespace.

The function should be case-insensitive (i.e., the input string “orange OrAnGe” is a match).

Some example input/output:

//returns 0

// returns 1
countAdjacentPairs('cat dog dog') 

// returns 1 (The first pair has been matched, and will be ignored from then on).
countAdjacentPairs('dog dog dog') 

// returns 2
countAdjacentPairs('cat cat dog dog cat')

Continue reading


[JS Practice] Anagram Detection

Title :

Anagram Detection


According to wikipedia :

An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; for example Doctor Who can be rearranged into Torchwood.

An anagram is the result of rearranging the letters of a word to produce a new word. (Ref wikipedia).

Note: anagrams are case insensitive


  • foefet is an anagram of toffee
  • Buckethead is an anagram of DeathCubeK

The challenge is to write the function isAnagram to return true if the word test is an anagram of the word original and false otherwise.

Continue reading

[JS Practice] Filter invalid login

Title :

Filter invalid login


While developing a website, you detect that some of the members have troubles logging in. Searching through the code you find that all logins ending with a “_” make problems. So you want to write a function that takes an array of pairs of login-names and e-mails, and outputs an array of all login-name, e-mails-pairs from the login-names that end with “_”.

If you have the input-array:

[ [ "foo", "foo@foo.com" ], [ "bar_", "bar@bar.com" ] ]

it should output

[ [ "bar_", "bar@bar.com" ] ]

Continue reading

[JS Practice] Valid The Coupon Code

Title :

Valid The Coupon Code


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



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.


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

Continue reading

[JS Practice] Sort characters

Title :

Sort characters


Write a function called sortGiftCode (sort_gift_code in Ruby) that accepts a string containing up to 26 unique alphabetical characters, and returns a string containing the same characters in alphabetical order.


sortGiftCode( 'abcdef' );//=> returns 'abcdef'
sortGiftCode( 'pqksuvy' );//=> returns 'kpqsuvy'
sortGiftCode( 'zyxwvutsrqponmlkjihgfedcba' );
//=> returns 'abcdefghijklmnopqrstuvwxyz'

Continue reading

[JS practice] javascript prototype Trim a String(重写trim方法)

Title :
Trim a String(重写javascript中的trim方法)

Description :
Extend the String prototype by a trim function, that returns the string with leading or trailing whitespaces removed.


PS: Of course, the original trim function was removed before 😉

Continue reading