[JS Practice] execute multiple functions successively on a value

Title :

Execute multiple functions successively on a value


Write a generic function chainer that takes a starting value, and an array of functions to execute on it. Return the final value after execution is complete.


function add(num) { 
   return num + 1 

function mult(num) { 
   return num * 30 

chain(2, [add, mult]); // returns 90;

Continue reading


[JS Practice] arithmetic list

Title :

Arithmetic list


Function accept three parameters :

  • first the first term in the sequence
  • c the constant that you are going to add ( since it is an arithmetic sequence…)
  • l the number of terms that should be returned

Sequence in wikipedia: Sequence


seqlist(0, 1, 5); // must return [0, 1, 2, 3, 4]

Continue reading

[JS Practice] Array Appender

Title :

Array Appender


You are the greatest chef on earth. No one boils eggs like you! Your restaurant is always full of guests, who love your boiled eggs. But when there is a greater order of boiled eggs, you need some time, because you have only one pot for your job. How much time do you need?

Your Task

Write a function called appendArrays that appends the items from array 2 onto array 1, returning the newly formed array.

For example if your 2 arrays were:

var array1 = [a,b,c]
var array2 = [1,2,3]

After using your appendArrays function, the result should be[a,b,c,1,2,3]

Your function should also be able to handle nested arrays.

For example, combining array [['x','x'],'B'] with array['c','D'] should return [['x','x'],'B','c','D'].

Your solution should account for a situation for either the first or second inputs aren’t actually arrays.

// basic test
Test.assertSimilar(appendArrays(['this'],['that']), ['this','that'])

// second input is not an array
Test.assertSimilar(appendArrays([1,2], [1]), [1,2,1])

// first input is not an array
Test.assertSimilar(appendArrays([2], [1,1,1]), [2,1,1,1])

Continue reading

[JS Practice] Sum of two array elements equals to target

Title :

Sum of two array elements equals to target


Write a function that takes an array of numbers (integers for the tests) and a target number. It should find two different items in the array that, when added together, give the target value. The indices of these items should then be returned in an array like so: [index1, index2].

The input will always be valid (numbers will be an array of length 2 or greater, and all of the items will be numbers; target will always be the sum of two different items from that array).


twosum([1,2,3], 4); // must return [0, 2]

Continue reading

[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