[JS Practice] Adjacent pairs in a string

Title :

Adjacent pairs in a string

Description:

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
countAdjacentPairs('') 

// 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

Description:

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

Examples

  • 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

Description:

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

[wget] create log file in /root directory

Context :

System : Ubuntu 12.04
Techs : shell(bash)

I have a bash shell script who calls a web service. The web service is wrote in PHP and it will return true if everything is OK.
The method that I execute the calling service is like this :

wget -T 0 http://host/program/myurl > /tmp/mylog

Problem :

Every time I execute the script shell with root, it will generate a file which is called myurl.x (x will be replaced by numbers) in my /root directory instead of in the /tmp/mylog, and this file contains only a number : 1, which I thought it means true.

Continue reading