Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 1.79 KB

16-basic-test-exercise.md

File metadata and controls

84 lines (58 loc) · 1.79 KB

Exericse 16

Question 1

Write a JavaScript program to check whether a string "Code" presents at 5th (index 4) position in a given string, if "Code" presents in the string return the string without "Code" otherwise return the original one.

Question 2

Write a JavaScript program to capitalize the first letter of each word of a given string.

Example string : 'the quick brown fox'
Expected Output : 'The Quick Brown Fox'

Question 3

Write a JavaScript program to check whether all the digits in a given number are the same or not.

Question 4

Write a JavaScript function that reverse a number.

Question 5

Write a JavaScript function to extract unique characters from a string.

Example string : "thequickbrownfoxjumpsoverthelazydog"
Expected Output : "thequickbrownfxjmpsvlazydg"

Question 6

Write a JavaScript function to chop a string into chunks of a given length. Test Data :

console.log(string_chop('w3resource'));
console.log(string_chop('w3resource',2));
console.log(string_chop('w3resource',3));
["w3resource"]
["w3", "re", "so", "ur", "ce"]
["w3r", "eso", "urc", "e"]

Question 7

Write a JavaScript function to find a word within a string. Test Data :

console.log(search_word('The quick brown fox', 'fox'));
console.log(search_word('aa, bb, cc, dd, aa', 'aa'));
Output :
"'fox' was found 1 times."
"'aa' was found 2 times."

Question 8

Create an array of numbers. Now filter out all the numbers from the array where number is in between 30-50. After filtering the numbers, add 20 to each number and finally print the sum of all numbers using reduce function.

Question 9

Convert below array:

[[1,2], [3,4], [5,6], [7,8], [9,10]]
to
[3,7,11,15,19]

Question 10

Print below pattern:

1 2 3 4 5
 2 3 4 5
  3 4 5
   4 5
    5