Starting from:

$25

Javascript - Classwork #1 - Solved

Nested Loops, Arrays, Strings

Input
Output
1 5 1
[1, 2, 3, 4, 5]
10 100 20
[10, 30, 50, 70, 90]
1 5 0.5
[1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
1.    Given an array․ Compute the length of the array. (without using .length)

Input
 
Output
[1, 12, 4]
3
 
[-1, 0, 1, 2]
4
 
[]
0
 
[-1, 0.4]
2
 
2.    Given an array of numbers. Print the sum of the elements in array.

Input
 
Output
[1, 12, 4]
17
 
[-1, 0, 1, 2]
2
 
[]
0
 
[-1, 0.4]
0.6
 
3.    Given three numbers a, b (a ≤ b) and step. Create an array of evenly spaced elements starting from a to b spaced by step.

4.    Given a string and a symbol. Find the number of occurrences of the symbol in the string.

Input
 
Output
“Some text here”, “a”
0
 
“another string”, “t”
2
 
Input
 
Output
[‘hello’, ‘,’ , ‘ ’, ‘world’]
“hello, world”
 
[‘a’, ‘c’, ‘a’]
“aca”
 
5.    Given a string. Check whether the string is palindrome or not.

Input
 
Output
“racecar”
“yes”
 
“T”
“Yes”
 
“”
“No”
 
“palindrome”
“No”
 
6.    Given an array of numbers. Find the maximum element in array.

Input
 
Output
[1, 10, 2, 2, 3]
10
 
[1, 4, 43, -112]
43
 
7.    Given an array of strings. Print the concatenation of all elements.

8.    Given an array. Create the array which elements are products between two neighbours.

Input
Output
[3, 7, 12, 5, 20, 0]
[21, 84, 60, 100, 0]
[1, 1, 4, 32, 6]
[1, 4, 128, 192 ]
9.    Given an array of numbers. Create an array containing only elements once.

Input
 
Output
[1, 2, 3, 3, 2, 5]
[1, 2, 3, 5]
 
[4, 4]
[4]
 
10.  Given a string and symbols. Change first symbol by the second one in the string.

Input
Output
“The results are not recorded yet”, “t”, “w”
“The resulws are now recorded yew”
“does the following code”, “o”, “0”
“d0es the f0ll0wing c0de”
11.  Insert a string. Create new string which is the mirror reverse of the inserted one around its center.

Input
 
Output
“stranger”
“ngerstra”
 
“rotator”
“torarot”
 
12.  Given an array of numbers. Print frequency of each unique number. (Frequency is the count of particular element divided by the count of all elements)

Input
Output
[1, 1, 2, 2, 3]
1: 0.4

2: 0.4

3: 0.2
[4, 4]
4: 1
[1, 2, 3]
1: 0.3333333333333333

2: 0.3333333333333333

3: 0.3333333333333333
13.  Print the following number pattern: (Change )

1

12

123

1234

12345

1234

123

12

1

More products