The Zero-ETL Approach: Enhancing Data Agility and Insight
TD2-JS-functions
1. CS425 - Web and Mobile Software Engineering
Dr. Lilia Sfaxi
8 février 2017
JavaScript Functions
Exercises
Go to http://codewars.com/ to train on any programming language you want!
I. Write a JavaScript function that accepts a string as a parameter and converts the first
letter of each word of the string in upper case.
Example string : 'the quick brown fox'
Expected Output : 'The Quick Brown Fox ‘
II. Write a JavaScript function that accepts a string as a parameter and finds the longest
word within the string.
Example string : 'Web Development Tutorial'
Expected Output : ‘Development'
III. Write a JavaScript function that accepts a string as a parameter and counts the
number of vowels within the string.
Note : As the letter 'y' can be regarded as both a vowel and a consonant, we do not count
'y' as vowel here.
Example string : 'The quick brown fox'
Expected Output : 5
IV. Write a JavaScript function that accepts a number as a parameter and checks if the
number is prime or not.
Note : A prime number (or a prime) is a natural number greater than 1 that has no
positive divisors other than 1 and itself.
JAVASCRIPT OBJECTS DR. LILIA SFAXI !1
MedTech
2. V. You are going to be given an array of integers. Your job is to take that array and
find an index N where the sum of the integers to the left of N is equal to the sum of the
integers to the right of N. If there is no index that would make this happen, return -1.
For example:
Let's say you are given the array {1,2,3,4,3,2,1}:
Your function will return the index 3, because at the 3rd position of the array, the sum
of left side of the index ({1,2,3}) and the sum of the right side of the index ({3,2,1}) both
equal 6.
VI. Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive
integer p we want to find a positive integer k, if it exists, such as the sum of the digits of n
taken to the successive powers of p is equal to k * n. In other words:
Is there an integer k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k
If it is the case we will return k, if not return -1.
Note: n, p will always be given as strictly positive integers.
JAVASCRIPT OBJECTS DR. LILIA SFAXI !2