JavaScript Practice Programs (Questions)
JavaScript Practice Programs (Questions)
1. Write a JavaScript program to display the current day and time in the following format.
Sample Output : Today is : Tuesday. Current time is : 10 PM : 30 : 38
2. Write a JavaScript program to print the contents of the current window.
3. Write a JavaScript program to get the current date.
Expected Output : mm-dd-yyyy, mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy
4. Write a JavaScript program to find the area of a triangle where lengths of the three of its sides are 5, 6, 7.
5. Write a JavaScript program to rotate the string 'The InfoMatrix Digital Services' in right direction by periodically
removing one letter from the end of the string and attaching it to the front.
6. Write a JavaScript program to determine whether a given year is a leap year in the Gregorian calendar.
7. Write a JavaScript program to find 1st January is being a Sunday between 2014 and 2050.
8. Write a JavaScript program where the program takes a random integer between 1 to 10, the user is then
prompted to input a guess number. If the user input matches with guess number, the program will display a
message "Good Work" otherwise display a message "Not matched".
9. Write a JavaScript program to calculate days left until next Christmas.
10. Write a JavaScript program to calculate multiplication and division of two numbers (input from user).
a. Sample form :
11. Write a JavaScript program to convert temperatures to and from Celsius, Fahrenheit.
[ Formula : c/5 = (f-32)/9 [ where c = temperature in Celsius and f = temperature in Fahrenheit ]
Expected Output :
60°C is 140 °F
45°F is 7.222222222222222°C
12. Write a JavaScript program to get the website URL (loading page).
13. Write a JavaScript exercise to create a variable using a user-defined name.
14. Write a JavaScript exercise to get the extension of a filename.
15. Write a JavaScript program to get the difference between a given number and 13, if the number is greater than 13
return double the absolute difference.
16. Write a JavaScript program to compute the sum of the two given integers. If the two values are same, then
returns triple their sum.
17. Write a JavaScript program to compute the absolute difference between a specified number and 19. Returns triple
their absolute difference if the specified number is greater than 19.
18. Write a JavaScript program to check two given numbers and return true if one of the number is 50 or if their sum
is 50.
19. Write a JavaScript program to check whether a given integer is within 20 of 100 or 400.
20. Write a JavaScript program to check from two given integers, whether one is positive and another one is
negative.
21. Write a JavaScript program to create a new string adding "Py" in front of a given string. If the given string begins
with "Py" then return the original string.
22. Write a JavaScript program to remove a character at the specified position of a given string and return the new
string.
23. Write a JavaScript program to create a new string from a given string changing the position of first and last
characters. The string length must be greater than or equal to 1.
24. Write a JavaScript program to create a new string from a given string with the first character of the given string
added at the front and back.
25. Write a JavaScript program to check whether a given positive number is a multiple of 3 or a multiple of 7.
26. Write a JavaScript program to create a new string from a given string taking the last 3 characters and added at
both the front and back. The string length must be 3 or more.
27. Write a JavaScript program to check whether a string starts with 'Java' and false otherwise.
28. Write a JavaScript program to check whether two given integer values are in the range 50..99 (inclusive). Return
true if either of them are in the said range.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
29. Write a JavaScript program to check whether three given integer values are in the range 50..99 (inclusive). Return
true if one or more of them are in the said range.
30. Write a JavaScript program to check whether a string "Script" presents at 5th (index 4) position in a given string, if
"Script" presents in the string return the string without "Script" otherwise return the original one.
31. Write a JavaScript program to find the largest of three given integers.
32. Write a JavaScript program to find a value which is nearest to 100 from two different given integer values.
33. Write a JavaScript program to check whether two numbers are in range 40..60 or in the range 70..100 inclusive.
34. Write a JavaScript program to find the larger number from the two given positive integers, the two numbers are in
the range 40..60 inclusive.
35. Write a program to check whether a specified character exists within the 2nd to 4th position in a given string.
36. Write a JavaScript program to check whether the last digit of the three given positive integers is same.
37. Write a JavaScript program to create new string with first 3 characters are in lower case from a given string. If the
string length is less than 3 convert all the characters in upper case.
38. Write a JavaScript program to check the total marks of a student in various examinations. The student will get A+
grade if the total marks are in the range 89..100 inclusive, if the examination is "Final-exam." the student will get
A+ grade and total marks must be greater than or equal to 90. Return true if the student get A+ grade or false
otherwise.
39. Write a JavaScript program to compute the sum of the two given integers, If the sum is in the range 50..80 return
65 other wise return 80.
40. Write a JavaScript program to check from two given integers whether one of them is 8 or their sum or difference
is 8.
41. Write a JavaScript program to check three given numbers, if the three numbers are same return 30 otherwise
return 20 and if two numbers are same return 40.
42. Write a JavaScript program to check whether three given numbers are increasing in strict mode or in soft mode.
Note: Strict mode -> 10, 15, 31 : Soft mode -> 24, 22, 31 or 22, 22, 31
43. Write a JavaScript program to check from three given numbers (non negative integers) that two or all of them
have the same rightmost digit.
44. Write a JavaScript program to check from three given integers that whether a number is greater than or equal to
20 and less than one of the others.
45. Write a JavaScript program to check two given integer values and return true if one of the number is 15 or if their
sum or difference is 15.
46. Write a JavaScript program to check two given non-negative integers that whether one of the number (not both)
is multiple of 7 or 11.
47. Write a JavaScript program to check whether a given number is presents in the range 40..10000.
For example 40 presents in 40 and 4000
48. Write a JavaScript program to reverse a given string.
49. Write a JavaScript program to replace every character in a given string with the character following it in the
alphabet.
50. Write a JavaScript program to capitalize the first letter of each word of a given string.
51. Write a JavaScript program to convert a given number to hours and minutes.
52. Write a JavaScript program to convert the letters of a given string in alphabetical order.
53. Write a JavaScript program to check whether the characters a and b are separated by exactly 3 places anywhere
(at least once) in a given string.
54. Write a JavaScript program to count the number of vowels in a given string.
55. Write a JavaScript program to check whether a given string contains equal number of p's and t's.
56. Write a JavaScript program to divide two positive numbers and return a string with properly formatted commas.
57. Write a JavaScript program to create a new string of specified copies (positive number) of a given string.
58. Write a JavaScript program to create a new string of 4 copies of the last 3 characters of a given original string. The
length of the given string must be 3 and above.
59. Write a JavaScript program to extract the first half of a string of even length.
60. Write a JavaScript program to create a new string without the first and last character of a given string.
61. Write a JavaScript program to concatenate two strings except their first character.
62. Write a JavaScript program to move last three character to the start of a given string. The string length must be
greater or equal to three.
63. Write a JavaScript program to create a string using the middle three characters of a given string of odd length. The
string length must be greater or equal to three.
64. Write a JavaScript program to concatenate two strings and return the result. If the length of the strings are not
same then remove the characters from the longer string.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
65. Write a JavaScript program to test whether a string end with "Script". The string length must be greater or equal
to 6.
66. Write a JavaScript program to display the city name if the string begins with "Los" or "New" otherwise return
blank.
67. Write a JavaScript program to create a new string from a given string, removing the first and last characters of the
string if the first or last character are 'P'. Return the original string if the condition is not satisfied.
68. Write a JavaScript program to create a new string using the first and last n c haracters from a given sting. The string
length must be greater or equal to n.
69. Write a JavaScript program to compute the sum of three elements of a given array of integers of length 3.
70. Write a JavaScript program to rotate the elements left of a given array of integers of length 3.
71. Write a JavaScript program to check whether 1 appears in first or last position of a given array of integers. The
array length must be greater or equal to 1.
72. Write a JavaScript program to check whether the first and last elements are equal of a given array of integers
length 3.
73. Write a JavaScript program to reverse the elements of a given array of integers length 3.
74. Write a JavaScript program to find the larger value between the first or last and set all the other elements with
that value. Display the new array.
75. Write a JavaScript program to create a new array taking the middle elements of the two arrays of integer and each
length 3.
76. Write a JavaScript program to create a new array taking the first and last elements from a given array of integers
and length must be greater or equal to 1.
77. Write a JavaScript program to test whether an array of integers of length 2 contains 1 or a 3.
78. Write a JavaScript program to test whether an array of integers of length 2 does not contain 1 or a 3.
79. Write a JavaScript program to test whether a given array of integers contains 30 and 40 twice. The array length
should be 0, 1, or 2.
80. Write a JavaScript program to swap the first and last elements of a given array of integers. The array length should
be at least 1.
81. Write a JavaScript program to add two digits of a given positive integer of length two.
82. Write a JavaScript to add two positive integers without carry.
83. Write a JavaScript to find the longest string from a given array of strings.
84. Write a JavaScript to replace each character of a given string by the next one in the English alphabet.
Note: 'a' will be replace by 'b' or 'z' would be replaced by 'a'.
85. Write a JavaScript code to divide a given array of positive integers into two parts. First element goes to first part,
second element goes to second part, and third element goes to first part and so on. Now compute the sum of two
parts and store into an array of size two.
86. Write a JavaScript program to find the types of a given angle.
i. Types of angles:
1. Acute angle: An angle between 0 and 90 degrees.
2. Right angle: An 90 degree angle.
3. Obtuse angle: An angle between 90 and 180 degrees.
4. Straight angle: A 180 degree angle.
87. Write a JavaScript program to check whether two arrays of integers of same length are similar or not. The arrays
will be similar if one array can be obtained from another array by swapping at most one pair of elements.
88. Write a JavaScript program to check whether two given integers are similar or not, if a given divisor divides both
integers and it does not divide either.
89. Write a JavaScript program to check whether it is possible to replace $ in a given expression x $ y = z with one of
the four signs +, -, * or / to obtain a correct expression.
For example x = 10, y = 30 and z = 300, we can replace $ with a multiple operator (*) to obtain x * y = z
90. Write a JavaScript program to find the kth greatest element of a given array of integers
91. Write a JavaScript program to find the maximum possible sum of some of its k consecutive numbers (numbers
that follow each other in order.) of a given array of positive integers.
92. Write a JavaScript program to find the maximal difference between any two adjacent elements of a given array of
integers.
93. Write a JavaScript program to find the maximal difference among all possible pairs of a given array of integers.
94. Write a JavaScript program to find the number which appears most in a given array of integers.
95. Write a JavaScript program to replace all the numbers with a specified number of a given array of integers.
96. Write a JavaScript program to compute the sum of absolute differences of consecutive numbers of a given array
of integers.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
97. Write a JavaScript program to find the shortest possible string which can create a string to make it a palindrome
by adding characters to the end of it.
98. Write a JavaScript program to switch case of the minimum possible number of letters to make a given string
written in the upper case or in the lower case.
Fox example "Write" will be write and "PHp" will be "PHP"
99. Write a JavaScript program to check whether it is possible to rearrange characters of a given string in such way
that it will become equal to another given string.
100. Write a JavaScript program to check whether there is at least one element which occurs in two given sorted
arrays of integers.
101.Write a JavaScript program to check whether a given string contains only Latin letters and no two uppercase and
no two lowercase letters are in adjacent positions.
102. Write a JavaScript program to find the number of inversions of a given array of integers.
Note: Two elements of the array a stored at positions i and j form an inversion if a[i] > a[j] and i < j.
103. Write a JavaScript program to find the maximal number from a given positive integer by deleting exactly one digit
of the given number.
104.Write a JavaScript program to find two elements of the array such that their absolute difference is not greater
than a given integer but is as close to the said integer.
105. Write a JavaScript program to find the number of times to replace a given number with the sum of its digits until
it convert to a single digit number.
106. Write a JavaScript program to divide an integer by another integer as long as the result is an integer and return
the result.
107.Write a JavaScript program to find the number of sorted pairs formed by its elements of a given array of integers
such that one element in the pair is divisible by the other one.
For example - The output of [1, 3, 2] ->2 - (1,3), (1,2).
The output of [2, 4, 6] -> 2 - (2,4), (2,6)
The output of [2, 4, 16] -> 3 - (2,4), (2,16), (4,16)
108.Write a JavaScript program to create the dot products of two given 3D vectors.
Note: The dot product is the sum of the products of the corresponding entries of the two sequences of numb ers.
109.Write a JavaScript program to sort an array of all prime numbers between 1 and a given integer.
110.Write a JavaScript program to find the number of even values in sequence before the first occurrence of a given
number.
111.Write a JavaScript program to check a number from three given numbers where two numbers are equal, find the
third one.
112.Write a JavaScript program to find the number of trailing zeros in the decimal representation of the factorial of a
given number.
113.Write a JavaScript program to calculate the sum of n + n/2 + n/4 + n/8 + .... where n is a positive integer and all
divisions are integer.
114.Write a JavaScript program to check whether a given string represents a correct sentence or not. A string is
considered correct sentence if it starts with the capital letter and ends with a full stop (.).
115.Write a JavaScript program to check whether a matrix is a diagonal matrix or not. In linear algebra, a diagonal
matrix is a matrix in which the entries outside the main diagonal are all zero (the diagonal from the upper left to
the lower right).
Example:
[1, 0, 0], [0, 2, 0], [0, 0, 3] ]) = true
[1, 0, 0], [0, 2, 3], [0, 0, 3] ]) = false
116.. Write a JavaScript program to find all the possible options to replace the hash in a string (Consists of digits and
one hash (#)) with a digit to produce an integer divisible by 3.
For a string "2*0", the output should be : ["210", "240", "270"]
117.Write a JavaScript program to check whether a given matrix is an identity matrix.
Note: In linear algebra, the identity matrix, or sometimes ambiguously called a unit matrix, of size n is the n ? n
square matrix with ones on the main diagonal and zeros elsewhere.
[[1, 0, 0], [0, 1, 0], [0, 0, 1]] -> true
[[1, 0, 0], [0, 1, 0], [1, 0, 1]] -> false
118.Write a JavaScript program to check whether a given number is in a given range.
119.Write a JavaScript program to check whether a given integer has an increasing digits sequence.
120.Write a JavaScript program to check whether a point lies strictly inside a given circle.
Input:
Center of the circle (x, y)
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
Radius of circle: r
Point inside a circle (a, b)
121.Write a JavaScript program to check whether a given matrix is lower triangular or not.
Note: A square matrix is called lower triangular if all the entries above the main diagonal are zero.
122.Write a JavaScript program to check whether a given array of integers represents either a strictly increasing or a
strictly decreasing sequence.
123.Write a JavaScript program to find whether the members of a given array of integers is a permutation of numbers
from 1 to a given integer.
124.Write a JavaScript program to create the value of NOR of two given booleans.
Note: In boolean logic, logical nor or joint denial is a truth-functional operator which produces a result that is the
negation of logical or. That is, a sentence of the form (p NOR q) is true precisely when neither p nor q is true - i.e.
when both of p and q are false
Sample Example:
For x = true and y = false, the output should be logical_Nor(x, y) = false; For x = false and y = false, the output
should be logical_Nor(x, y) = true.
125.Write a JavaScript program to find the longest string from a given array.
126.Write a JavaScript program to get the largest even number from an array of integers.
127.Write a JavaScript program to reverse the order of the bits in a given integer.
56 -> 111000 after reverse 7 -> 111
234 -> 11101010 after reverse 87 -> 1010111
128.Write a JavaScript program to find the smallest round number that is not less than a given value.
Note: A round number is informally considered to be an integer that ends with one or more zeros.[3] So, 590 is
rounder than 592, but 590 is less round than 600.
129.Write a JavaScript program to find the smallest prime number strictly greater than a given number.
130.Write a JavaScript program to find the number of even digits in a given integer.
131.Write a JavaScript program to create an array of prefix sums of the given array.
In computer science, the prefix sum, cumulative sum, inclusive scan, or simply scan of a sequence of numbers x0,
x1, x2, ... is a second sequence of numbers y0, y1, y2, ..., the sums of prefixes of the input sequence:
y0 = x0
y1 = x0 + x1
y2 = x0 + x1+ x2
..
132.Write a JavaScript program to find all distinct prime factors of a given integer.
133.Write a JavaScript program to check whether a given fraction is proper or not.
Note: There are two types of common fractions, proper or improper. When the numerator and the denominator
are both positive, the fraction is called proper if the numerator is less than the denominator, and improper
otherwise.
134.Write a JavaScript program to change the characters (lower case) in a string where a turns into z, b turns into y, c
turns into x, ..., n turns into m, m turns into n, ..., z turns into a.
135.Write a JavaScript program to remove all characters from a given string that appear more than once
136.Write a JavaScript program to replace the first digit in a string (should contains at least digit) with $ character.
137.Write a JavaScript program to test whether a given integer is greater than 15 return the given number, otherwise
return 15.
138.Write a JavaScript program to reverse the bits of a given 16 bits unsigned short integer.
139.Write a JavaScript program to find the position of a rightmost round number in an array of integers. Returns 0 if
there are no round number.
Note: A round number is informally considered to be an integer that ends with one or more zeros.
140.Write a JavaScript program to check whether all the digits in a given number are the same or not.
141.Write a JavaScript program to find the number of elements which presents in both of the given arrays.
142.Write a JavaScript program to simplify a given absolute path for a file in Unix-style.
143.Write a JavaScript program to sort the strings of a given array of strings in the order of increasing lengths.
Note: Do not change the order if the lengths of two string are same.
144.Write a JavaScript program to break an address of an url and put it's part into an array.
145.Write a JavaScript program to find the maximum integer n such that 1 + 2 + ... + n <= a given integer.
146.Write a JavaScript program to compute the sum of cubes of all integer from 1 to a given integer.
147.Write a JavaScript program to compute the sum of all digits that occur in a given string.
148.Write a JavaScript program to swap two halves of a given array of integers of even length.
149.Write a JavaScript program to change the capitalization of all letters in a given string.
150.Write a JavaScript program to swap pairs of adjacent digits of a given integer of even length.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
151.Write a JavaScript program to compare two objects to determine if the first one contains equivalent property
values to the second one.
152.Write a JavaScript program to copy a string to the clipboard.
153.Write a JavaScript program to converts a comma-separated values (CSV) string to a 2D array.
154.Write a JavaScript program to convert a comma-separated values (CSV) string to a 2D array of objects. The first
row of the string is used as the title row.
155.Write a JavaScript program to convert an array of objects to a comma-separated values (CSV) string that contains
only the columns specified.
156.Write a JavaScript program to target a given value in a nested JSON object, based on the given key.
157.Write a JavaScript program to converts a specified number to an array of digits.
158.Write a JavaScript program to filter out the specified values from a specified array. Return the original array
without the filtered values.
159.Write a JavaScript program to combine the numbers of a given array into an array containing all combinations .
160.Write a JavaScript program to extract out the values at the specified indexes from a specified array.
161.Write a JavaScript program to generate a random hexadecimal color code.
162.Write a JavaScript program to removes non-printable ASCII characters from a given string.
163.Write a JavaScript program to convert the length of a given string in bytes.
164.Write a JavaScript program to replace the names of multiple object keys with the values provided.
165.Write a JavaScript program to return the minimum-maximum value of an array, after applying the provided
function to set comparing rule.
166.Write a JavaScript function that returns true if the provided predicate function returns true for all elements in a
collection, false otherwise.
167.Write a JavaScript program to split values of two given arrays into two groups. If an element in filter is truthy, the
corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
168.Write a JavaScript program to remove specified elements from the left of a given array of elements.
169.Write a JavaScript program to remove specified elements from the right of a given array of elements.
170.Write a JavaScript program to extend a 3-digit color code to a 6-digit color code.
171.Write a JavaScript program to get every nth element in a given array.
172.Write a JavaScript program to filter out the non-unique values in an array.
173.Write a JavaScript program to filter out the non-unique values in an array, based on a provided comparator
function.
174.Write a JavaScript program to dcapitalize the first letter of a string.
175.Write a JavaScript program to create a new array out of the two supplied by creating each possible pair from the
arrays.
176.Write a JavaScript program that will return true if the string is y/yes or false if the string is n/no.
177.Write a JavaScript program to find every element that exists in any of the two given arrays once, using a provided
comparator function.
178.Write a JavaScript program to measure the time taken by a function to execute.
179.Write a JavaScript program to convert a value to a safe integer.
180.Write a JavaScript program to filter out the element(s) of a given array, that have one of the specified values.
181.Write a JavaScript program to find all elements in a given array except for the first one. Return the whole array if
the array's length is 1.
182.Write a JavaScript program to get the sum of a given array, after mapping each element to a value using the
provided function.
183.Write a JavaScript program to get a random number in the specified range.
184.Write a JavaScript program to get a random integer in the specified range.
185.Write a JavaScript program to get an array of given n random integers in the specified range.
186.Write a JavaScript program to create a function that invokes each provided function with the arguments it
receives and returns the results.
187.Write a JavaScript program to get a sorted array of objects ordered by properties and orders.
188.Write a JavaScript program to pad a string on both sides with the specified character, if it's shorter than the
specified length.
189.Write a JavaScript program to remove the key-value pairs corresponding to the given keys from an object.
190.Write a JavaScript program to create an array of key-value pair arrays from a given object.
191.Write a JavaScript program to create an object from the given key-value pairs.
192.Write a JavaScript program to get a customized coalesce function that returns the first argument that returns true
from the provided argument validation function.
193.Write a JavaScript program to change function that accepts an array into a variadic function.
194.Write a JavaScript program to remove falsey values from a given array.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
195.Write a JavaScript program to split values into two groups, if an element in filter is truthy, the corresponding
element in the collection belongs to the first group; otherwise, it belongs to the second group.
196.Write a JavaScript program to curry (curries) a function.
197.Write a JavaScript program to perform a deep comparison between two values to determine if they are
equivalent.
198.Write a JavaScript program to get an array of function property names from own (and optionally inherited)
enumerable properties of an object.
199.Write a JavaScript program to retrieve a set of properties indicated by the given selectors from an object.
200.Write a JavaScript program to convert an integer to a suffixed string, adding am or pm based on its value.
201.Write a JavaScript program to get an object containing the parameters of the current URL.
202.Write a JavaScript program to group the elements of a given array based on the given function.
203.Write a JavaScript program to Initialize a two dimension array of given width and height and value.
204.Write a JavaScript program to initialize an array containing the numbers in the specified range where start and
end are inclusive with their common difference step.
205.Write a JavaScript program to Join all given URL segments together, then normalizes the resulting URL.
206.Write a JavaScript program to check whether all elements in a given array are equal or not.
207.Write a JavaScript program to compute the average of an array, after mapping each element to a value using the
provided function.
208.Write a JavaScript program to split values into two groups according to a predicate function, which specifies which
group an element in the input collection belongs to.
209.Write a JavaScript program to create a function that invokes fn with a given context, optionally adding any
additional supplied parameters to the beginning of the arguments.
210.Write a JavaScript program to create a function that invokes the method at a given key of an object, optionally
adding any additional supplied parameters to the beginning of the arguments.
211.Write a JavaScript program to cast the provided value as an array if it's not one.
212.Write a JavaScript program to chain asynchronous functions.
213.Write a JavaScript program to clone a given regular expression.
214.Write a JavaScript program to get the first non-null / undefined argument.
215.Write a JavaScript program to add special characters to text to print in color in the console (combined with
console.log()).
216.Write a JavaScript program to perform right-to-left function composition.
217.Write a JavaScript program to perform left-to-right function composition.
218.Write a JavaScript program that accepts a converging function and a list of branching functions and returns a
function that applies each branching function to the arguments and the results of the branching functions are
passed as arguments to the converging function.
219.Write a JavaScript program to group the elements of an array based on the given function and returns the count
of elements in each group.
220.Write a JavaScript program to count the occurrences of a value in an array.
221.Write a JavaScript program to create a deep clone of an object.
222.Write a JavaScript program to detect whether the website is being opened in a mobile device or a
desktop/laptop.
223.Write a JavaScript program to return the difference between two arrays, after applying the provided function to
each array element of both.
224.Write a JavaScript program to filter out all values from an array for which the comparator function does not return
true.
225.Write a JavaScript program to compute the new ratings between two or more opponents using the Elo rating
system. It takes an array of pre-ratings and returns an array containing post-ratings. The array should be ordered
from best performer to worst performer (winner -> loser).
226.Write a JavaScript program to execute a provided function once for each array element, starting from the array's
last element.
227.Write a JavaScript program to iterate over all own properties of an object, running a callback for each one.
228.Write a JavaScript program to invert the key-value pairs of an object, without mutating it. The corresponding
inverted value of each inverted key is an array of keys responsible for generating the inverted value. If a function is
supplied, it is applied to each inverted key.
229.Write a JavaScript program to take any number of iterable objects or objects with a length property and returns
the longest one.
230.Write a JavaScript program to implement the Luhn Algorithm used to validate a variety of identification numbers,
such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
231.Write a JavaScript program to create an object with keys generated by running the provided function f or each key
and the same values as the provided object.
232.Write a JavaScript program to map the values of an array to an object using a function, where the key -value pairs
consist of the original value as the key and the mapped value.
233.Write a JavaScript program to create a new string with the results of calling a provided function on every character
in the calling string.
234.Write a JavaScript program to create an object with the same keys as the provided object and values generated by
running the provided function for each value.
235.Write a JavaScript program to replace all but the last number of characters with the specified mask character.
236.Write a JavaScript program to get the maximum value of an array, after mapping each element to a value using
the provided function.
237.Write a JavaScript program to get the n maximum elements from the provided array. If n is greater than or equal
to the provided array's length, then return the original array(sorted in descending order).
238.Write a JavaScript program to get the median of an array of numbers.
239.Write a JavaScript program to negates a predicate function.
240.Write a JavaScript program to nest a given flat array of objects linked to one another recursively.
241.Write a JavaScript program that will return true if the provided predicate function returns false for all elements in
a collection, false otherwise.
242.Write a JavaScript program to create a function that gets the argument at index n. If n is negative, the nth
argument from the end is returned.
243.Write a JavaScript program to remove an event listener from an element.
244.Write a JavaScript program to move the specified amount of elements to the end of the array.
245.Write a JavaScript program to add an event listener to an element with the ability to use event delegation.
246.Write a JavaScript program to pick the key-value pairs corresponding to the given keys from an object.
247.Write a JavaScript program to create an object composed of the properties the given function returns truthy for.
The function is invoked with two arguments: (value, key).
248.Write a JavaScript program to filter an array of objects based on a condition while also filtering out unspecified
keys.
249.Write a JavaScript program to hash a given input string into a whole number.
250.Write a JavaScript program to create an array of elements, grouped based on the position in the original arrays
and using function as the last value to specify how grouped values should be combined.
251.Write a JavaScript program to return the object associating the properties to the values of a given array of valid
property identifiers and an array of values.
252.Write a JavaScript program to create an array of elements, grouped based on the position in the original arrays.
253.Write a JavaScript program to convert a given string into an array of words.
254.Write a JavaScript program to test a value, x, against a predicate function. If true, return fn(x). Else, return x.
255.Write a JavaScript program that return true if the given value is a number, false otherwise.
256.Write a JavaScript program to create an array of elements, ungrouping the elements in an array produced by zip
and applying the provided function.
257.Write a JavaScript program to get all unique values (form the right side of the array) of an array, based on a
provided comparator function.
258.Write a JavaScript program to get all unique values of an array, based on a provided comparator function.
259.Write a JavaScript program to get the nth element of a given array.
260.Write a JavaScript program to get every element that exists in any of the two arrays once.
261.Write a JavaScript program to build an array, using an iterator function and an initial seed value.
262.Write a JavaScript program to unflatten an object with the paths for keys.
263.Write a JavaScript program to unescape escaped HTML characters.
264.Write a JavaScript program to uncurry a function up to depth n.
265.Write a JavaScript program to create a function that accepts up to one argument, ignoring any additional
arguments.
266.Write a JavaScript program to check if the predicate (second argument) is truthy on all elements of a collection
(first argument).
267.Write a JavaScript program to truncate a string up to a specified length.
268.Write a JavaScript program to apply a function against an accumulator and each key in the object (from left to
right).
269.Write a JavaScript program to create tomorrow's date in a string representation.
270.Write a JavaScript program to convert a string to snake case.
271.Write a JavaScript program to convert a value to a safe integer.
272.Write a JavaScript program to add an ordinal suffix to a number.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
273.Write a JavaScript program to convert a string to kebab case.
274.Write a JavaScript program to reduce a given Array-like into a value hash (keyed data store).
275.Write a JavaScript program to convert a float-point arithmetic to the Decimal mark form and It will make a comma
separated string from a number.
276.Write a JavaScript program to create a specified currency formatting from a given number.
277.Write a JavaScript program to Iterate over a callback n times.
278.Write a JavaScript program to get removed elements of a given array until the passed function returns true.
279.Write a JavaScript program to get removed elements from the end of a given array until the passed function
returns true.
280.Write a JavaScript program to remove n elements from the end of a given array.
281.Write a JavaScript program to get an array with n elements removed from the beginning from a given array
282.Write a JavaScript program to get the symmetric difference between two given arrays, using a provided function
as a comparator.
283.Write a JavaScript program to get the symmetric difference between two given arrays, after applying the provided
function to each array element of both.
284.Write a JavaScript program to get the symmetric difference between two given arrays.
285.Write a JavaScript program to get the sum of the powers of all the numbers from start to end (both inclusive).
286.Write a JavaScript program to generate all permutations of a string (contains duplicates).
287.Write a JavaScript program to perform stable sorting of an array, preserving the initial indexes of items when their
values are the same. Do not mutate the original array, but returns a new array instead.
288.Write a JavaScript program that takes a variadic function and returns a closure that accepts an array of arguments
to map to the inputs of the function.
289.Write a JavaScript program to split a multiline string into an array of lines.
290.Write a JavaScript program to get the highest index at which value should be inserted into array in order to
maintain its sort order, based on a provided iterator function.
291.Write a JavaScript program to get the highest index at which value should be inserted into array in order to
maintain its sort order.
292.Write a JavaScript program to get the lowest index at which value should be inserted into array in order to
maintain its sort order.
293.Write a JavaScript program to sort the characters of a string Alphabetically.
294.Write a JavaScript program to get an array of elements that appear in both arrays.
295.Write a JavaScript program to randomize the order of the values of an array, returning a new array.
296.Write a JavaScript program to create a shallow clone of an object.
297.Write a JavaScript program to serialize a cookie name-value pair into a Set-Cookie header string.
298.Write a JavaScript program to hash the input string into a whole number.
299. Write a JavaScript program to get a random element from an array.
300.Write a JavaScript program to run a given array of promises in series.
301.Write a JavaScript program to run a function in a separate thread by using a Web Worker, allowing long running
functions to not block the UI.
302.Write a JavaScript program to round a number to a specified amount of digits.
303.Write a JavaScript program to reverse the order of the characters in the string.
304.Write a JavaScript program to create an object composed of the properties the given function returns falsey for.
The function is invoked with two arguments: (value, key).
305.Write a JavaScript program that takes a predicate and array, like Array.filter(), but only keeps x if pred(x) returns
false.
306.Write a JavaScript program to apply a function against an accumulator and each element in the array (from left to
right), returning an array of successively reduced values.
307.Write a JavaScript program to redirect to a specified URL.
308.Write a JavaScript program to create a function that invokes the provided function with its arguments arranged
according to the specified indexes.
309.Write a JavaScript program to get an array of lines from the specified file.
310.Write a JavaScript program to mutate the original array to filter out the values specified, based on a given iterator
function.
311.Write a JavaScript program to mutate the original array to filter out the values specified. Returns the removed
elements.
312.Write a JavaScript program to convert an asynchronous function to return a promise.
313.Write a JavaScript program to convert a number in bytes to a human-readable string.
314.Write a JavaScript program that will return the singular or plural form of the word based on the input number.
315.Write a JavaScript program to perform left-to-right function composition.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
316.Write a JavaScript program to perform left-to-right function composition for asynchronous functions
317.Write a JavaScript program to calculate how many numbers in the given array are less or equal to the given value
using the percentile formula.
318.Write a JavaScript program to group the elements into two arrays, depending on the provided function's
truthiness for each element.
319.Write a JavaScript program to create a function that invokes fn with partials appended to the arguments it
receives.
320.Write a JavaScript program to create a function that invokes fn with partials prepended to the arguments it
receives.
321.Write a JavaScript program to parse an HTTP Cookie header string and return an object of all cookie name-value
pairs.
322.Write a JavaScript program to create a function that invokes the provided function with its arguments
transformed.
323.Write a JavaScript program to get the nth element of an given array.
324.Write a JavaScript program to convert a NodeList to an array.
325.Write a JavaScript program to get the index of the function in an array of functions which executed the fastest.
326.Write a JavaScript program to get the n minimum elements from the provided array. If n is greater than or equ al
to the provided array's length, then return the original array(sorted in ascending order).
327.Write a JavaScript program to get the minimum value of an array, after mapping each element to a value using the
provided function.
328.Write a JavaScript program to create a new object from the combination of two or more objects.
329.Write a JavaScript program to compare two objects to determine if the first one contains equivalent property
values to the second one, based on a provided function.
330.Write a JavaScript program to create a new object from the specified object, where all the keys are in lowercase.
331.Write a JavaScript program to get the last element from an given array.
332.Write a JavaScript program to join all elements of an array into a string and returns this string. Uses a separator
and an end separator.
333.Write a JavaScript program to check if the provided argument is a valid JSON.
334.Write a JavaScript program to check if a given string is upper case or not.
335.Write a JavaScript program that will return true if the specified value is undefined, false otherwise.
336.Write a JavaScript program to check if the given argument is a symbol.
337.Write a JavaScript program to check if the given argument is a string.
338.Write a JavaScript program that will return 1 if the array is sorted in ascending order, -1 if it is sorted in descending
order or 0 if it is not sorted.
339.Write a JavaScript program that will return true if an object looks like a Promise, false otherwise
340.Write a JavaScript program to get a boolean determining if the passed value is primitive or not.
341.Write a JavaScript program to check if the provided integer is a prime number is not.
342.Write a JavaScript program to check if the provided value is an object created by the Object constructor.
343.Write a JavaScript program to check if a value is object-like. Check if the provided value is not null and its typeof is
equal to 'object'.
344.Write a JavaScript program to get a boolean determining if the passed value is an object or not.
345.Write a JavaScript program to check if a given argument is a number.
346.Write a JavaScript program that will return true if the specified value is null, false otherwise.
347.Write a JavaScript program to check if a string is lower case or not.
348.Write a JavaScript program to check if the given argument is a function.
349.Write a JavaScript program that will return true if the given number is even, false otherwise.
350.Write a JavaScript program that will return true if a value is an empty object, collection, map or set, has no
enumerable properties or is any type that is not considered a collection.
351.Write a JavaScript program to check if the first numeric argument is divisible by the second one.
352.Write a JavaScript program to check if a given number is even or not.
353.Write a JavaScript program to determine if the current runtime environment is a browser so that front-end
modules can run on the server (Node) without throwing errors.
354.Write a JavaScript program that will check if the given argument is a native boolean element.
355.Write a JavaScript program to check if the provided argument is array-like (i.e. is iterable).
356.Write a JavaScript program to check if a given string is an anagram of another string (case-insensitive, ignores
spaces, punctuation and special characters).
357.Write a JavaScript program to that will return true if the given string is an absolute URL, false otherwise.
358.Write a JavaScript program to check if the provided value is of the specified type.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
359.Write a JavaScript program to get a list of elements that exist in both arrays, using a provided comparator
function.
360.Write a JavaScript program to get a list of elements that exist in both arrays, after applying the provided function
to each array element of both.
361.Write a JavaScript program to get a list of elements that exist in both arrays.
362.Write a JavaScript program to create a n-dimensional array with given value.
363.Write a JavaScript program to initialize and fill an array with the specified values.
364.Write a JavaScript program to Initializes an array containing the numbers in the specified range (in reverse) where
start and end are inclusive with their common difference step.
365.Write a JavaScript program to get all the elements of an array except the last one.
366.Write a JavaScript program to get all indices of val in an array. If val never occurs, returns [].
367. Write a JavaScript program to check if the given number falls within the given range.
368.Write a JavaScript program to get the number of times a function executed per second. hz is the unit for hertz, the
unit of frequency defined as one cycle per second.
369.Write a JavaScript program to calculate the Hamming distance between two values.
370.Write a JavaScript program to get the native type of a value. Returns lowercased constructor name of value,
"undefined" or "null" if value is undefined or null.
371.Write a JavaScript program to get a string of the form HH:MM:SS from a Date object.
372.Write a JavaScript program that initializes an array containing the numbers in the specified range where start and
end are inclusive and the ratio between two terms is step. Returns an error if step equals 1.
373.Write a JavaScript program to calculate the greatest common divisor between two or more numbers/arrays.
374.Write a JavaScript program to remove HTML/XML tags from string.
375.Write a JavaScript program to get the standard deviation of an array of numbers.
376.Write a JavaScript program to get n random elements at unique keys from array up to the size of array.
377.Write a JavaScript program to remove elements from an array for which the given function returns false
378.Write a JavaScript program to log the name of a function.
379.Write a JavaScript program to convert a string from camelcase.
380.Write a JavaScript program to get the human readable format of the given number of milliseconds.
381.Write a JavaScript program to iterate over all own properties of an object in reverse, running a callback for each
one.
382.Write a JavaScript program that takes a function as an argument, then makes the first argument the last.
383.Write a JavaScript program to flatten an object with the paths for keys.
384.Write a JavaScript program to flatten a given array up to the specified depth.
385.Write a JavaScript program to get the last key that satisfies the provided testing function, otherwise undefined is
returned.
386.Write a JavaScript program to get the first key that satisfies the provided testing function. Otherwise return
undefined.
387.Write a JavaScript program to generate an array, containing the Fibonacci sequence, up until the nth term.
388.Write a JavaScript program to calculate the factorial of a number.
389.Write a JavaScript program to escape a string to use in a regular expression.
390.Write a JavaScript program that will return true if the parent element contains the child element, false otherwise.
391.Write a JavaScript program to remove elements in an array until the passed function returns true. Returns the
remaining elements in the array.
392.Write a JavaScript program to remove elements from the end of an array until the passed function returns true.
Returns the remaining elements in the array.
393.Write a JavaScript program to get the distance between two given points.
394.Write a JavaScript program to get the difference between two given arrays.
395.Write a JavaScript program to Invokes the provided function after wait milliseconds.
396.Write a JavaScript program to convert an given angle from degrees to radians.
397.Write a JavaScript program that Assigns default values for all properties in an object that are undefined.
398.Write a JavaScript program to deep flatten an array.
399.Write a JavaScript program to get the current URL.
400.Write a JavaScript program to create an element from a string (without appending it to the document).
401.Write a JavaScript program to write a JSON object to a file.
402.Write a JavaScript program to convert the values of RGB components to a color code.
403.Write a JavaScript program to generate a UUID in a browser.
404.Write a JavaScript program to generate a UUID in Node.JS. Use crypto API to generate a UUID, compliant with
RFC4122 version 4.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
405.Write a JavaScript program that will return true if the provided predicate function returns true for at least one
element in a collection, false otherwise.
406.Write a JavaScript program to check if two given numbers are approximately equal to each other.
407.Write a JavaScript program to convert a 2D array to a comma-separated values (CSV) string.
408.Write a JavaScript program to create a function that accepts up to n arguments, ignoring any additional
arguments.
409.Write a JavaScript program to decode a string of data which has been encoded using base-64 encoding.
410.Write a JavaScript program to evaluate the binomial coefficient of two integers n and k.
411. Write a JavaScript program that will return true if the bottom of the page is visible, false otherwise.
412.Write a JavaScript program to create a base-64 encoded ASCII string from a String object in which each character
in the string is treated as a byte of binary data.
413.Write a JavaScript program to capitalize the first letter of a string.
414.Write a JavaScript program to capitalize the first letter of every word in a string.
415.Write a JavaScript program to chunk an array into smaller arrays of a specified size.
416.Write a JavaScript program to clamp a number within the inclusive range specified by the given boundary values a
and b.
417.Write a JavaScript function that reverse a number.
Example x = 32243;
Expected Output : 34223
418.Write a JavaScript function that checks whether a passed string is palindrome or not?
A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.
419.Write a JavaScript function that generates all combinations of a string.
Example string : 'dog'
Expected Output : d,do,dog,o,og,g
420.Write a JavaScript function that returns a passed string with letters in alphabetical order.
Example string : 'webmaster'
Expected Output : 'abeemrstw'
Assume punctuation and numbers symbols are not included in the passed string.
421.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 '
422.Write a JavaScript function that accepts a string as a parameter and find the longest word within the string.
Example string : 'Web Development Tutorial'
Expected Output : 'Development'
423.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
424.Write a JavaScript function that accepts a number as a parameter and check 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.
425.Write a JavaScript function which accepts an argument and returns the type.
Note : There are six possible values that typeof returns: object, boolean, function, number, string, and undefined.
426.Write a JavaScript function which returns the n rows by n columns identity matrix.
427.Write a JavaScript function which will take an array of numbers stored and find the second lowest and second
greatest numbers, respectively.
Sample array : [1,2,3,4,5]
Expected Output : 2,4
428.Write a JavaScript function which says whether a number is perfect.
According to Wikipedia : In number theory, a perfect number is a positive integer that is equal to the sum of its
proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its
aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including
itself).
Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6.
Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6. The next
perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.
429.Write a JavaScript function to compute the factors of a positive integer.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
430.Write a JavaScript function to convert an amount to coins.
Sample function : amountTocoins(46, [25, 10, 5, 2, 1])
Here 46 is the amount. and 25, 10, 5, 2, 1 are coins.
Output : 25, 10, 10, 1
431.Write a JavaScript function to compute the value of b n where n is the exponent and b is the bases. Accept b and n
from the user and display the result.
432.Write a JavaScript function to extract unique characters from a string.
Example string : "thequickbrownfoxjumpsoverthelazydog"
Expected Output : "thequickbrownfxjmpsvlazydg"
433.Write a JavaScript function to get the number of occurrences of each letter in specified string.
434.Write a function for searching JavaScript arrays with a binary search.
Note : A binary search searches by splitting an array into smaller and smaller chunks until it finds the desired value.
435.Write a JavaScript function that returns array elements larger than a number.
436.Write a JavaScript function that generates a string id (specified length) of random characters.
Sample character list : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
437.Write a JavaScript function to get all possible subset with a fixed length (for example 2) combinations in an array.
Sample array : [1, 2, 3] and subset length is 2
Expected output : [[2, 1], [3, 1], [3, 2], [3, 2, 1]]
438.Write a JavaScript function that accepts two arguments, a string and a letter and the function will count the
number of occurrences of the specified letter within the string.
Sample arguments : 'InfoMatrix.com', 'o'
Expected output : 2
439.Write a JavaScript function to find the first not repeated character.
Sample arguments : 'abacddbec'
Expected output : 'e'
440.Write a JavaScript function to apply Bubble Sort algorithm.
Note : According to wikipedia "Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm
that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and
swapping them if they are in the wrong order".
Sample array : [12, 345, 4, 546, 122, 84, 98, 64, 9, 1, 3223, 455, 23, 234, 213]
Expected output : [3223, 546, 455, 345, 234, 213, 122, 98, 84, 64, 23, 12, 9, 4, 1]
441.Write a JavaScript function that accept a list of country names as input and returns the longest country name as
output.
Sample function : Longest_Country_Name(["Australia", "Germany", "United States of America"])
Expected output : "United States of America"
442.Write a JavaScript function to find longest substring in a given a string without repeating characters.
443.Write a JavaScript function that returns the longest palindrome in a given string.
Note: According to Wikipedia "In computer science, the longest palindromic substring or longest symmetric factor
problem is the problem of finding a maximum-length contiguous substring of a given string that is also a
palindrome. For example, the longest palindromic substring of "bananas" is "anana". The longest palindromic
substring is not guaranteed to be unique; for example, in the string "abracadabra", there is no palindromic
substring with length greater than three, but there are two palindromic substrings with length three, namely,
"aca" and "ada".
In some applications it may be necessary to return all maximal palindromic substrings (that is, all substrings that
are themselves palindromes and cannot be extended to larger palindromic substrings) rather than returning only
one substring or returning the maximum length of a palindromic substring.
444.Write a JavaScript program to pass a 'JavaScript function' as parameter.
445.Write a JavaScript function to get the function name.
446.Write a JavaScript program to calculate the factorial of a number.
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less
than or equal to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120
447.Write a JavaScript program to find the greatest common divisor (gcd) of two positive numbers.
448.Write a JavaScript program to get the integers in range (x, y).
Example : range(2, 9)
Expected Output : [3, 4, 5, 6, 7, 8]
449.Write a JavaScript program to compute the sum of an array of integers.
Example : var array = [1, 2, 3, 4, 5, 6]
Expected Output : 21
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
450.Write a JavaScript program to compute the exponent of a number.
Note : The exponent of a number says how many times the base number is used as a factor.
8 2 = 8 x 8 = 64. Here 8 is the base and 2 is the exponent.
451.Write a JavaScript program to get the first n Fibonacci numbers.
Note : The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . Each subsequent number
is the sum of the previous two.
452.Write a JavaScript program to check whether a number is even or not.
453.Write a JavaScript program for binary search.
Sample array : [0,1,2,3,4,5,6]
console.log(l.br_search(5)) will return '5'
454.Write a merge sort program in JavaScript.
Sample array : [34,7,23,32,5,62]
Sample output : [5, 7, 23, 32, 34, 62]
455.Write a JavaScript program that accept two integers and display the larger.
456.Write a JavaScript conditional statement to find the sign of product of three numbers. Display an alert box with
the specified sign.
Sample numbers : 3, -7, 2
Output : The sign is –
457.Write a JavaScript conditional statement to sort three numbers. Display an alert box to show the result.
Sample numbers : 0, -1, 4
Output : 4, 0, -1
458.Write a JavaScript conditional statement to find the largest of five numbers. Display an alert box to show the
result.
Sample numbers : -5, -2, -6, 0, -1
Output : 0
459.Write a JavaScript for loop that will iterate from 0 to 15. For each iteration, it will check if the current number is
odd or even, and display a message to the screen.
Sample Output :
"0 is even"
"1 is odd"
"2 is even" ……..
460.Write a JavaScript program which compute, the average marks of the following students Then, this average is used
to determine the corresponding grade.
David 80
Vinoth 77
Divya 88
Ishitha 95
Thomas 68
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
Range Grade
<60 F
<=70 D
461.Write a JavaScript program which iterates the integers from 1 to 100. But for
multiples of three print "Fizz" instead of the number and for the multiples of <=80 C
five print "Buzz". For numbers which are multiples of both three and five print
"FizzBuzz". <=90 B
462.According to Wikipedia a happy number is defined by the following process :
"Starting with any positive integer, replace the number by the sum of the =100 A
squares of its digits, and repeat the process until the number equals 1 (where it
will stay), or it loops endlessly in a cycle which does not include 1. Those
numbers for which this process ends in 1 are happy numbers, while those that d o not end in 1 are unhappy
numbers (or sad numbers)".
Write a JavaScript program to find and print the first 5 happy numbers.
463.Write a JavaScript program to find the armstrong numbers of 3 digits.
Note : An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the
number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
464.Write a JavaScript program to construct the following pattern, using a nested for loop.
*
**
* **
* ** *
* ** * *
465.Write a JavaScript program to compute the lowest common divisor (LCD) of two positive integers.
466.Write a JavaScript program to sum the multiples of 3 and 5 under 1000.
467.. Write a JavaScript function to convert a number from one base to another.
Note : Both bases must be between 2 and 36.
Test Data :
console.log(base_convert('E164',16,8));
console.log(base_convert(1000,2,8));
"160544"
"10"
468.Write a JavaScript function to convert a binary number to a decimal number.
Test Data :
console.log(bin_to_dec('110011'));
console.log(bin_to_dec('100'));
51
4
469.Write a JavaScript function to convert a decimal number to binary, hexadecimal or octal number.
Test Data :
console.log(dec_to_bho(120,'B'));
console.log(dec_to_bho(120,'H'));
console.log(dec_to_bho(120,'O'));
"1111000"
"78"
"170"
470.Write a JavaScript function to generate a random integer.
Test Data :
console.log(rand(20,1));
console.log(rand(1,10));
console.log(rand(6));
console.log(rand());
15
5
1
0
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
471.Write a JavaScript function to format a number up to specified decimal places.
Test Data :
console.log(decimals(2.100212, 2));
console.log(decimals(2.100212, 3));
console.log(decimals(2100, 2));
"2.10"
"2.100"
"2100.00"
472.Write a JavaScript function to find the highest value in an array.
Test Data :
console.log(max([12,34,56,1]));
console.log(max([-12,-34,0,-56,-1]));
56
0
473.Write a JavaScript function to find the lowest value in an array.
Test Data :
console.log(min([12,34,56,1]));
console.log(min([-12,-34,0,-56,-1]));
1
-56
474.Write a JavaScript function to get the greatest common divisor (gcd) of two integers.
Note :
According to Wikipedia - In mathematics, the greatest common divisor (gcd) of two or more integers, when at
least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For
example, the GCD of 8 and 12 is 4.
Test Data :
console.log(gcd_two_numbers(12, 13));
console.log(gcd_two_numbers(9, 3));
Output :
1
3
475.Write a JavaScript function to find the GCD (greatest common divisor) of more than 2 integers.
Test Data :
console.log(gcd_more_than_two_numbers([3,15,27]));
console.log(gcd_more_than_two_numbers([5,10,15,25]));
Output :
3
5
476.Write a JavaScript function to get the least common multiple (LCM) of two numbers.
Note :
According to Wikipedia - A common multiple is a number that is a multiple of two or more integers. The common
multiples of 3 and 4 are 0, 12, 24, .... The least common multiple (LCM) of two numbers is the smallest number
(not zero) that is a multiple of both.
Test Data :
console.log(lcm_two_numbers(3,15));
console.log(lcm_two_numbers(10,15));
Output :
15
30
477.Write a JavaScript function to get the least common multiple (LCM) of more than 2 integers.
Test Data :
console.log(lcm_more_than_two_numbers([100,90,80,7]));
console.log(lcm_more_than_two_numbers([5,10,15,25]));
Output :
25200
150
478.Write a JavaScript function to find out if a number is a natural number or not.
Note :
Natural numbers are whole numbers from 1 upwards : 1, 2, 3, and so on ... or from 0 upwards in some area of
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
mathematics: 0, 1, 2, 3 and so on ...
No negative numbers and no fractions.
Test Data :
console.log(is_Natural(-15));
console.log(is_Natural(1));
console.log(is_Natural(10.22));
console.log(is_Natural(10/0));
Output :
false
true
false
false
479.Write a JavaScript function to test if a number is a power of 2.
Test Data :
console.log(power_of_2(16));
console.log(power_of_2(18));
console.log(power_of_2(256));
Output :
true
false
true
480.Write a JavaScript function to round a number to a given decimal places.
Test Data :
console.log(precise_round(12.375,2));
console.log(precise_round(-10.3079499, 3));
console.log(precise_round(10.49999,0));
console.log(precise_round(10.49999,2));
Output :
12.38
-10.308
10
10.50
481.Write a JavaScript function to check whether a value is an integer or not.
Note : Integer - A number which is not a fraction; a whole number.
Test Data : Output :
console.log(is_Int(23)); true
console.log(is_Int(4e2)); true
console.log(is_Int(NaN)); false
console.log(is_Int(23.75)); false
console.log(is_Int(-23)); true
482. Write a JavaScript function to check to check whether a variable is numeric or not.
Test Data : Output :
console.log(is_Numeric(12)); true
console.log(is_Numeric('abcd')); false
console.log(is_Numeric('12')); true
console.log(is_Numeric(' ')); false
console.log(is_Numeric(1.20)); true
console.log(is_Numeric(-200)); true
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
484. Write a JavaScript function to calculate the product of values in an array.
Test Data : Output :
console.log(product([1,2,3])); 6
console.log(product([100,-200,3])); -60000
console.log(product([1,2,'a',3])); 6
Arranging binomial coefficients into rows for successive values of n, and in which k ranges from 0 to n, gives a
triangular array called Pascal's triangle.
Test Data : Output :
console.log(binomial(8,3)); 56
console.log(binomial(10,2)); 45
487. Write a JavaScript function that Convert an integer into a Roman Numeral in javaScript.
488. Write a JavaScript function that Convert Roman Numeral to Integer.
489. Write a JavaScript function to create a UUID identifier.
Note :
According to Wikipedia - A universally unique identifier (UUID) is an identifier standard used in software
construction. A UUID is simply a 128-bit value. The meaning of each bit is defined by any of several variants.
For human-readable display, many systems use a canonical format using hexadecimal text with inserted
hyphen characters. For example : de305d54-75b4-431b-adb2-eb6b9e546014
490. Write a JavaScript function to round a number to a specified number of digits and strip extra zeros (if any).
Test Data :
var a = -4.55555;
console.log(result);
-4.5556
var a = 5.0001000;
console.log(result);
5.0001
491. Write a JavaScript function to make currency math (add, subtract, multiply, division etc.).
Test Data :
n1 = '$40.24', n2 = '$21.57';
492. Write a JavaScript function to calculate the nth root of a number.
Test Data :
console.log(nthroot(64, 2));
8
console.log(nthroot(64, -2));
0.125
493. Write a JavaScript function to calculate degrees between 2 points with inverse Y axis.
Test Data :
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
console.log(pointDirection(1, 0, 12, 0));
0
console.log(pointDirection(1, 0, 1, 10));
90
494. Write a JavaScript function to round up an integer value to the next multiple of 5.
Test Data :
console.log(int_round5(32));
35
console.log(int_round5(137));
140
495. Write a JavaScript function to convert a positive number to negative number.
Test Data :
console.log(pos_to_neg(15));
-15
496. Write a JavaScript function to cast a square root of a number to an integer.
Test Data :
console.log(sqrt_to_int(17));
4
497. Write a JavaScript function to get the highest number from three different numbers.
Test Data :
console.log(highest_of_three(-5, 4, 2));
4
498. Write a JavaScript function to calculate the percentage (%) of a number.
Test Data :
console.log(percentage(1000, 47.12));
471.2
499. Write a JavaScript function to convert an angle from degrees to radians.
Test Data :
console.log(degrees_to_radians(45));
0.7853981633974483
500. Write a JavaScript function to convert radians to degrees.
Test Data :
console.log(radians_to_degrees(0.7853981633974483));
45
501. Write a JavaScript function for the Pythagorean theorem.
According to Wikipedia : In mathematics, the Pythagorean theorem, also known as Pythagoras' theorem, is a
relation in Euclidean geometry among the three sides of a right triangle. It states that the square of the
hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides. The
theorem can be written as an equation relating the lengths of the sides a, b and c, often called the
"Pythagorean equation".
Test Data :
console.log(pythagorean(4, 3));
5
502. Write a JavaScript function which will return values that are powers of two.
Test Data :
console.log(isPower_of_two(64));
true
console.log(isPower_of_two(94));
false
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
This is called the kth falling factorial power of x.
515. Write a JavaScript function to calculate Lanczos approximation gamma.
In mathematics, the Lanczos approximation is a method for computing the Gamma function numerically,
published by Cornelius Lanczos in 1964. It is a practical alternative to the more popular Stirling's
approximation for calculating the Gamma function with fixed precision.
516. Write a JavaScript program to add two complex numbers.
A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and
i is the imaginary unit, that satisfies the equation i 2 = −1. In this expression, a is the real part and b is the
imaginary part of the complex number.
517. Write a JavaScript program to subtract two complex numbers.
518. Write a JavaScript program to multiply two complex numbers.
519. Write a JavaScript program to divide two complex numbers.
520. Write a JavaScript function to check whether an `input` is an array or not.
Test Data :
console.log(is_array('InfoMatrix'));
console.log(is_array([1, 2, 4, 0]));
false
true
521. Write a JavaScript function to clone an array.
Test Data :
console.log(array_Clone([1, 2, 4, 0]));
console.log(array_Clone([1, 2, [4, 0]]));
[1, 2, 4, 0]
[1, 2, [4, 0]]
522. Write a JavaScript function to get the first element of an array. Passing a parameter 'n' will return the first 'n'
elements of the array.
Test Data :
console.log(first([7, 9, 0, -2]));
console.log(first([],3));
console.log(first([7, 9, 0, -2],3));
console.log(first([7, 9, 0, -2],6));
console.log(first([7, 9, 0, -2],-3));
Expected Output :
7
[]
[7, 9, 0]
[7, 9, 0, -2]
[]
523. Write a JavaScript function to get the last element of an array. Passing a parameter 'n' will return the last 'n'
elements of the array.
Test Data :
console.log(last([7, 9, 0, -2]));
console.log(last([7, 9, 0, -2],3));
console.log(last([7, 9, 0, -2],6));
Expected Output :
-2
[9, 0, -2]
[7, 9, 0, -2]
524. Write a simple JavaScript program to join all elements of the following array into a string.
Sample array : myColor = ["Red", "Green", "White", "Black"];
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
Expected Output :
"Red,Green,White,Black"
"Red,Green,White,Black"
"Red+Green+White+Black"
525. Write a JavaScript program which accept a number as input and insert dashes (-) between each two even
numbers. For example if you accept 025468 the output should be 0-254-6-8.
526. Write a JavaScript program to sort the items of an array.
Sample array : var arr1 = [ 3, 8, 7, 6, 5, -4, 3, 2, 1 ];
Sample Output : -4,-3,1,2,3,5,6,7,8
527. Write a JavaScript program to find the most frequent item of an array.
Sample array : var arr1=[3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3];
Sample Output : a ( 5 times )
528. Write a JavaScript program which accept a string as input and swap the case of each character. For example
if you input 'The Quick Brown Fox' the output should be 'tHE qUICK bROWN fOX'.
529. Write a JavaScript program which prints the elements of the following array.
Note : Use nested for loops.
Sample array : var a = [[1, 2, 1, 24], [8, 11, 9, 4], [7, 0, 7, 27], [7, 4, 28, 14], [3, 10, 26, 7]] ;
Sample Output :
"row 0"
" 1"
" 2"
" 1"
" 24"
"row 1"
------
------
530. Write a JavaScript program to find the sum of squares of a numeric vector.
531. Write a JavaScript program to compute the sum and product of an array of integers.
532. Write a JavaScript program to add items in an blank array and display the items.
Sample Screen :
533. Write a JavaScript program to remove duplicate items from an array (ignore case sensitivity).
534. We have the following arrays :
color = ["Blue ", "Green", "Red", "Orange", "Violet", "Indigo", "Yellow "];
o = ["th","st","nd","rd"]
Write a JavaScript program to display the colors in the following way :
"1st choice is Blue ."
"2nd choice is Green."
"3rd choice is Red."
------ -------
Note : Use ordinal numbers to tell their position.
535. Write a JavaScript program to find the leap years in a given range of years.
536. Write a JavaScript program to shuffle an array.
537. Write a JavaScript program to perform a binary search.
Note : A binary search or half-interval search algorithm finds the position of a specified input value within an
array sorted by key value.
Sample array :
var items = [1, 2, 3, 4, 5, 7, 8, 9];
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
Expected Output :
console.log(binary_Search(items, 1)); //0
console.log(binary_Search(items, 5)); //4
538. There are two arrays with individual values, write a JavaScript program to compute the sum of each
individual index value from the given arrays.
Sample array :
array1 = [1,0,2,3,4];
array2 = [3,5,6,7,8,13];
Expected Output :
[4, 5, 8, 10, 12, 13]
539. Write a JavaScript program to find duplicate values in a JavaScript array.
540. Write a JavaScript program to flatten a nested (any depth) array. If you pass shallow, the array will only be
flattened a single level.
Sample Data :
console.log(flatten([1, [2], [3, [[4]]],[5,6]]));
[1, 2, 3, 4, 5, 6]
console.log(flatten([1, [2], [3, [[4]]],[5,6]], true));
[1, 2, 3, [[4]], 5, 6]
541. Write a JavaScript program to compute the union of two arrays.
Sample Data :
console.log(union([1, 2, 3], [100, 2, 1, 10]));
[1, 2, 3, 10, 100]
542. Write a JavaScript function to find the difference of two arrays.
Test Data :
console.log(difference([1, 2, 3], [100, 2, 1, 10]));
["3", "10", "100"]
console.log(difference([1, 2, 3, 4, 5], [1, [2], [3, [[4]]],[5,6]]));
["6"]
console.log(difference([1, 2, 3], [100, 2, 1, 10]));
["3", "10", "100"]
543. Write a JavaScript function to remove. 'null', '0', '""', 'false', 'undefined' and 'NaN' values from an array.
Sample array : [NaN, 0, 15, false, -22, '',undefined, 47, null]
Expected result : [15, -22, 47]
544. . Write a JavaScript function to sort the following array of objects by title value.
Sample object :
var library = [
{ author: 'Bill Gates', title: 'The Road Ahead', libraryID: 1254},
{ author: 'Steve Jobs', title: 'Walter Isaacson', libraryID: 4264},
{ author: 'Suzanne Collins', title: 'Mockingjay: The Final Book of The Hunger Games',
libraryID: 3245}
];
Expected result :
[[object Object] {
author: "Suzanne Collins",
libraryID: 3245,
title:"Mockingjay:The Final Book of The Hunger Games"
}, [object Object] {
author: "Bill Gates",
libraryID: 1254,
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
title: "The Road Ahead"
}, [object Object] {
author: "Steve Jobs",
libraryID: 4264,
title: "Walter Isaacson"
}]
545. Write a JavaScript program to find a pair of elements (indices of the two numbers) from an given array whose sum
equals a specific target number.
Input: numbers= [10,20,10,40,50,60,70], target=50
Output: 2, 3
546. Write a JavaScript function to retrieve the value of a given property from all elements in an array.
Sample array : [NaN, 0, 15, false, -22, '',undefined, 47, null]
Expected result : [15, -22, 47]
547. Write a JavaScript function to find the longest common starting substring in a set of strings.
Sample array : console.log(longest_common_starting_substring(['go', 'google']));
Expected result : "go"
548. Write a JavaScript function to fill an array with values (numeric, string with one character) on supplied bounds.
Test Data :
console.log(num_string_range('a', "z", 2));
["a", "c", "e", "g", "i", "k", "m", "o", "q", "s", "u", "w", "y"]
549. Write a JavaScript function to merge two arrays and removes all duplicates elements.
Test data :
var array1 = [1, 2, 3];
var array2 = [2, 30, 1];
console.log(merge_array(array1, array2));
[3, 2, 30, 1]
550. Write a JavaScript function to remove a specific element from an array.
Test data :
console.log(remove_array_element([2, 5, 9, 6], 5));
[2, 9, 6]
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
555. Write a JavaScript function to create a specified number of elements with pre-filled numeric value array.
Test Data :
console.log(array_filled(6, 0));
[0, 0, 0, 0, 0, 0]
console.log(array_filled(4, 11));
[11, 11, 11, 11]
556. Write a JavaScript function to create a specified number of elements with pre-filled string value array.
Test Data :
console.log(array_filled(3, 'default value'));
["default value", "default value", "default value"]
console.log(array_filled(4, 'password'));
["password", "password", "password", "password"]
557. Write a JavaScript function to move an array element from one position to another.
Test Data :
console.log(move([10, 20, 30, 40, 50], 0, 2));
[20, 30, 10, 40, 50]
console.log(move([10, 20, 30, 40, 50], -1, -2));
[10, 20, 30, 50, 40]
558. Write a JavaScript function to filter false, null, 0 and blank values from an array.
Test Data :
console.log(filter_array_values([58, '', 'abcd', true, null, false, 0]));
[58, "abcd", true]
559. Write a JavaScript function to generate an array of specified length, filled with integer numbers, increase by one from
starting position.
Test Data :
console.log(array_range(1, 4));
[1, 2, 3, 4]
console.log(array_range(-6, 4));
[-6, -5, -4, -3]
560. Write a JavaScript function to generate an array between two integers of 1 step length.
Test Data :
console.log(rangeBetwee(4, 7));
[4, 5, 6, 7]
console.log(rangeBetwee(-4, 7));
[-4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
561. Write a JavaScript function to find the unique elements from two arrays.
Test Data :
console.log(difference([1, 2, 3], [100, 2, 1, 10]));
["1", "2", "3", "10", "100"]
console.log(difference([1, 2, 3, 4, 5], [1, [2], [3, [[4]]],[5,6]]));
["1", "2", "3", "4", "5", "6"]
console.log(difference([1, 2, 3], [100, 2, 1, 10]));
["1", "2", "3", "10", "100"]
562. Write a JavaScript function to create an array of arrays, ungrouping the elements in an array produced by zip.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
Test Data :
unzip([['a', 1, true], ['b', 2, false]])
unzip([['a', 1, true], ['b', 2]])
Expected Output:
[["a","b"],[1,2],[true,false]]
[["a","b"],[1,2],[true]]
563. Write a JavaScript function to create an object from an array, using the specified key and excluding it from each value.
Test Data :
indexOn([ { id: 10, name: 'apple' }, { id: 20, name: 'orange' } ], x => x.id)
Expected Output:
{"undefined":{"id":20,"name":"orange"}}
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
5 7 5. Write a JavaScript function to get the minimum date from an array of dates.
Test Data :
console.log(min_date(['2015/02/01', '2015/02/02', '2015/01/03']));
Output :
"2015/01/03"
5 7 6. Write a JavaScript function that will return the number of minutes in hours and minutes.
Test Data :
console.log(timeConvert(200));
Output :
"200 minutes = 3 hour(s) and 20 minute(s)."
5 7 9. Write a JavaScript function to count the number of days passed since beginning of the year.
Test Data :
console.log(days_passed(new Date(2015, 0, 15)));
15
console.log(days_passed(new Date(2015, 11, 14)));
348
5 8 2. Write a JavaScript function to get the day of the month, 2 digits with leading zeros.
Test Data :
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
d= new Date(2015, 10, 1);
console.log(day_of_the_month(d));
"01"
5 8 3. Write a JavaScript function to get a textual representation of a day (three letters, Mon through Sun).
Test Data :
dt = new Date(2015, 10, 1);
console.log(short_Days(dt));
"Sun"
5 8 4. Write a JavaScript function to get a full textual representation of the day of the week (Sunday th rough Saturday).
Test Data :
dt = new Date(2015, 10, 1);
console.log(long_Days(dt));
"Sunday"
5 8 5. Write a JavaScript function to get ISO-8601 numeric representation of the day of the week (1 (for Monday) to 7 (for
Sunday)).
Test Data :
dt = new Date(2015, 10, 1);
console.log(ISO_numeric_date(dt));
7
5 8 6. Write a JavaScript function to get English ordinal suffix for the day of the month, 2 characters (st, nd, rd or th.).
Test Data :
dt = new Date(2015, 10, 1);
console.log(english_ordinal_suffix(dt));
"1st"
5 8 7. Write a JavaScript function to get ISO-8601 week number of year, weeks starting on Monday.
Example : 42 (the 42nd week in the year)
Test Data :
dt = new Date(2015, 10, 1);
console.log(ISO8601_week_no(dt));
44
5 8 8. Write a JavaScript function to get a full textual representation of a month, such as January or June.
Test Data :
dt = new Date(2015, 10, 1);
console.log(full_month(dt));
"November"
5 8 9. Write a JavaScript function to get a numeric representation of a month, with leading zeros (01 through 12).
Test Data :
dt = new Date(2015, 10, 1);
console.log(numeric_month(dt));
"11"
5 9 0. Write a JavaScript function to get a short textual representation of a month, three letters (Jan through Dec).
Test Data :
dt = new Date(2015, 10, 1);
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
console.log(short_months(dt));
"Nov"
5 9 2. Write a JavaScript function to get lowercase Ante meridiem and Post meridiem.
5 9 3. Write a JavaScript function to get uppercase Ante meridiem and Post meridiem.
5 9 5. Write a JavaScript function to get 12-hour format of an hour with leading zeros.
Test Data :
dt = new Date(1989, 10, 1);
console.log(hours_with_zeroes(dt));
"12"
5 9 6. Write a JavaScript function to get 24-hour format of an hour without leading zeros.
Test Data :
dt = new Date(1989, 10, 1);
console.log(hours_without_zeroes(dt));
0
5 9 7. Write a JavaScript function to get minutes with leading zeros (00 to 59).
Test Data :
dt = new Date(1989, 10, 1);
console.log(minutes_with_leading_zeros(dt));
"00"
5 9 8. Write a JavaScript function to get seconds with leading zeros (00 through 59).
Test Data :
dt = new Date(1989, 10, 1);
console.log(seconds_with_leading_zeros(dt));
"00"
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
5 9 9. Write a JavaScript function to get Timezone.
Test Data :
dt = new Date();
console.log(seconds_with_leading_zeros(dt));
"India Standard Time"
6 0 0. Write a JavaScript function to find whether or not the date is in daylights savings time.
Test Data :
dt = new Date();
console.log(daylights_savings(dt));
1
6 0 6. Write a JavaScript function to get time differences in minutes between two dates.
Test Data :
dt1 = new Date("October 13, 2014 11:11:00");
dt2 = new Date("October 13, 2014 11:13:00");
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
console.log(diff_minutes(dt1, dt2));
2
6 0 7. Write a JavaScript function to get time differences in hours between two dates.
Test Data :
dt1 = new Date("October 13, 2014 08:11:00");
dt2 = new Date("October 13, 2014 11:13:00");
console.log(diff_hours(dt1, dt2));
3
6 0 8. Write a JavaScript function to get time differences in days between two dates.
Test Data :
dt1 = new Date("October 13, 2014 08:11:00");
dt2 = new Date("October 19, 2014 11:13:00");
console.log(diff_days(dt1, dt2));
6
6 0 9. Write a JavaScript function to get time differences in weeks between two dates.
Test Data :
dt1 = new Date("June 13, 2014 08:11:00");
dt2 = new Date("October 19, 2014 11:13:00");
console.log(diff_weeks(dt1, dt2));
18
6 1 0. Write a JavaScript function to get time differences in months between two dates.
Test Data :
dt1 = new Date("June 13, 2014 08:11:00");
dt2 = new Date("October 19, 2014 11:13:00");
console.log(diff_months(dt1, dt2));
5
6 1 1. Write a JavaScript function to get time differences in years between two dates.
Test Data :
dt1 = new Date("June 13, 2014 08:11:00");
dt2 = new Date("October 19, 2017 11:13:00");
console.log(diff_years(dt1, dt2));
3
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
console.log(is_string([1, 2, 4, 0]));
false
6 1 8. Write a JavaScript function to split a string and convert it into an array of words.
Test Data :
console.log(string_to_array("Robin Singh"));
["Robin", "Singh"]
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
6 3 2. Write a JavaScript function to chop a string into chunks of a given length.
Test Data :
console.log(string_chop('InfoMatrix'));
console.log(string_chop('InfoMatrix',2));
console.log(string_chop('InfoMatrix',3));
["InfoMatrix"]
["w3", "re", "so", "ur", "ce"]
["w3r", "eso", "urc", "e"]
.
6 3 3. Write a JavaScript function to count the occurrence of a substring in a string.
Test Data :
console.log(count("The quick brown fox jumps over the lazy dog", 'the'));
Output :
2
console.log(count("The quick brown fox jumps over the lazy dog", 'fox',false));
Output :
1
.
6 3 4. Write a JavaScript function to escape a HTML string.
Test Data :
console.log(escape_HTML('<a href="javascript-string-exercise-17.php" target="_blank">'));
Output :
"<a href="javascript-string-exercise-17.php" target="_blank">"
.
6 3 5. Write a JavaScript function that can pad (left, right) a string to get to a determined length.
Test Data :
console.log(formatted_string('0000',123,'l'));
console.log(formatted_string('00000000',123,''));
Output :
"0123"
"12300000"
.
6 3 6. Write a JavaScript function to repeat a string a specified times.
Test Data :
console.log(repeat_string('a', 4));
console.log(repeat_string('a'));
Output :
"aaaa"
"Error in string or count."
.
6 3 7. Write a JavaScript function to get a part of a string after a specified character.
Test Data :
console.log(subStrAfterChars('InfoMatrix: JavaScript Exercises', ':','a'));
console.log(subStrAfterChars('InfoMatrix: JavaScript Exercises', 'E','b'));
Output :
"InfoMatrix"
"xercises"
.
6 3 8. Write a JavaScript function to strip leading and trailing spaces from a string.
Test Data :
console.log(strip('InfoMatrix '));
console.log(strip(' InfoMatrix'));
console.log(strip(' InfoMatrix '));
Output :
"InfoMatrix"
"InfoMatrix"
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
"InfoMatrix"
.
6 3 9. Write a JavaScript function to truncate a string to a certain number of words.
Test Data :
console.log(truncate('The quick brown fox jumps over the lazy dog', 4));
Output :
"The quick brown fox"
.
6 4 0. Write a JavaScript function to alphabetize a given string.
Alphabetize string : An individual string can be alphabetized. This rearranges the letters so they are sorted A to Z.
Test Data :
console.log(alphabetize_string('United States'));
Output :
"SUadeeinsttt"
.
6 4 1. Write a JavaScript function to remove the first occurrence of a given 'search string' from a string.
Test Data :
console.log(remove_first_occurrence("The quick brown fox jumps over the lazy dog", 'the'));
Output :
"The quick brown fox jumps over lazy dog"
.
6 4 2. Write a JavaScript function to convert ASCII to Hexadecimal format.
Test Data :
console.log(ascii_to_hexa('12'));
console.log(ascii_to_hexa('100'));
Output :
"3132"
"313030"
.
6 4 3. Write a JavaScript function to convert Hexadecimal to ASCII format.
Test Data :
console.log(hex_to_ascii('3132'));
console.log(hex_to_ascii('313030'));
Output :
"12"
"100"
.
6 4 4. 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."
.
6 4 5. Write a JavaScript function check if a string ends with specified suffix.
Test Data :
console.log(string_endsWith('JS PHP PYTHON','PYTHON'));
true
console.log(string_endsWith('JS PHP PYTHON',''));
false
.
6 4 6. Write a JavaScript function to escapes special characters (&, <, >, ', ") for use in HTML.
Test Data :
console.log(escape_html('PHP & MySQL'));
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
"PHP & MySQL"
console.log(escape_html('3 > 2'));
"3 > 2"
.
6 4 7. Write a JavaScript function to remove?non-printable ASCII chars.
Test Data :
console.log(remove_non_ascii('???????PHP-MySQ L??????'));
"PHP-MySQL"
.
6 4 8. Write a JavaScript function to remove non-word characters.
Test Data :
console.log(remove_non_word('PHP ~!@#$%^&*()+`-={}[]|\\:";\'/?><., MySQL'));
"PHP - MySQL"
.
6 4 9. Write a JavaScript function to convert a string to title case.
Test Data :
console.log(sentenceCase('PHP exercises. python exercises.'));
"Php Exercises. Python Exercises."
.
6 5 0. Write a JavaScript function to remove HTML/XML tags from string.
Test Data :
console.log(strip_html_tags('<p><strong><em>PHP Exercises</em></strong></p>'));
"PHP Exercises"
.
6 5 1. Write a JavaScript function to create a Zerofilled value with optional +, - sign.
Test Data :
console.log(zeroFill(120, 5, '-'));
"+00120"
console.log(zeroFill(29, 4));
"0029"
.
6 5 2. Write a JavaScript function to test case insensitive (except special Unicode characters) string comparison.
Test Data :
console.log(compare_strings('abcd', 'AbcD'));
true
console.log(compare_strings('ABCD', 'Abce'));
false
.
6 5 3. Write a JavaScript function to create a case-insensitive search.
Test Data :
console.log(case_insensitive_search('JavaScript Exercises', 'exercises'));
"Matched"
console.log(case_insensitive_search('JavaScript Exercises', 'Exercises'));
"Matched"
console.log(case_insensitive_search('JavaScript Exercises', 'Exercisess'));
"Not Matched"
.
6 5 4. Write a JavaScript function to Uncapitalize? the first character of a string.
Test Data :
console.log(Uncapitalize('Js string exercises'));
"js string exercises"
.
6 5 5. Write a JavaScript function to Uncapitalize the first letter of each word of a string.
Test Data :
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
console.log(unCapitalize_Words('Js String Exercises'));
"js string exercises"
.
6 5 6. Write a JavaScript function to capitalize each word in the string.
Test Data :
console.log(capitalizeWords('js string exercises'));
"JS STRING EXERCISES"
.
6 5 7. Write a JavaScript function to uncapitalize each word in the string.
Test Data :
console.log(unCapitalizeWords('JS STRING EXERCISES'));
"js string exercises"
.
6 5 8. Write a JavaScript function to test whether the character at the provided (character) index is upper case.
Test Data :
console.log(isUpperCaseAt('Js STRING EXERCISES', 1));
false
.
6 5 9. Write a JavaScript function to test whether the character at the provided (character) index is lower case.
Test Data :
console.log(isLowerCaseAt ('Js STRING EXERCISES', 1));
true
.
6 6 0. Write a JavaScript function to get humanized number with the correct suffix such as 1st, 2nd, 3rd or 4th.
Test Data :
console.log(humanize(1));
console.log(humanize(20));
console.log(humanize(302));
"1st"
"20th"
"302nd"
.
6 6 1. Write a JavaScript function to test whether a string starts with a specified string.
Test Data :
console.log(startsWith('js string exercises', 'js'));
true
.
6 6 2. Write a JavaScript function to test whether a string ends with a specified string.
Test Data :
console.log(endsWith('JS string exercises', 'exercises'));
true
.
6 6 3. Write a JavaScript function to get the successor of a string.
Note: The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost
character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing
a letter results in another letter of the same case. If the increment generates a carry, the character to the left of it is
incremented. This process repeats until there is no carry, adding an additional character if necessary.
Example :
string.successor("abcd") == "abce"
string.successor("THX1138") == "THX1139"
string.successor("< >") == "< >"
string.successor("1999zzz") == "2000aaa"
string.successor("ZZZ9999") == "AAAA0000"
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
Test Data :
console.log(successor('abcd'));
console.log(successor('3456'));
"abce"
"3457"
.
6 6 4. Write a JavaScript function to get unique guid (an acronym for 'Globally Unique Identifier?) of the specified length, or
32 by default.
Test Data :
console.log(guid());
console.log(guid(15));
"hRYilcoV7ajokxsYFl1dba41AyE0rUQR"
"b7pwBqrZwqaDrex"
665. Write a JavaScript program to test the first character of a string is uppercase or not.
6 6 9. Write a JavaScript program that work as a trim function (string) using regular expression.
6 7 3. Write a JavaScript function to check whether a given value is an valid url or not.
6 7 4. Write a JavaScript function to check whether a given value is alpha numeric or not.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
6 7 5. Write a JavaScript function to check whether a given value is time string or not.
6 7 6. Write a JavaScript function to check whether a given value is US zip code or not.
6 7 7. Write a JavaScript function to check whether a given value is UK Post Code or not.
6 7 8. Write a JavaScript function to check whether a given value is Canada Post Code or not.
6 7 9. Write a JavaScript function to check whether a given value is a social security number or not.
6 8 0. Write a JavaScript function to check whether a given value is hexadecimal value or not.
6 8 1. Write a JavaScript function to check whether a given value is hexcolor value or not.
6 8 2. Write a JavaScript function to check whether a given value represents a domain or not.
6 8 4. Write a JavaScript function to check a given value contains alpha, dash and underscore.
6 8 6. Here is a sample html file with a submit button. Now modify the style of the paragraph text through javascript code.
Sample HTML file :
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS DOM paragraph style</title>
</head>
<body>
<p id ='text'>JavaScript Exercises - InfoMatrix</p>
<div>
<button id="jsstyle"
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
onclick="js_style()">Style</button>
</div>
</body>
</html>
Clicking on the button the font, font size, and color of the paragraph text will be changed.
6 8 7. Write a JavaScript function to get the values of First and Last name of the following form.
Sample HTML file :
<!DOCTYPE html>
<html><head>
<meta charset=utf-8 />
<title>Return first and last name from a form - InfoMatrix</title>
</head><body>
<form id="form1" onsubmit="getFormvalue()">
First name: <input type="text" name="fname" value="David"><br>
Last name: <input type="text" name="lname" value="Beckham"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
6 8 9. Here is a sample html file with a submit button. Write a JavaScript function to get the value of the href, hreflang, rel,
target, and type attributes of the specified link.
<!DOCTYPE html>
<html><head>
<meta charset=utf-8 />
</head>
<body>
<p><a id="w3r" type="text/html" hreflang="en-us" rel="nofollow" target="_self"
href="https://www.InfoMatrix.com/">InfoMatrix</a></p>
<button onclick="getAttributes()">Click here to get attributes value</button>
</body></html>
6 9 1. Write a JavaScript function that accept row, column, (to identify a particular cell) and a string to update the content of
that cell.
Sample HTML file :
<!DOCTYPE html>
<html><head>
<meta charset=utf-8 />
<title>Change the content of a cell</title>
</head><body>
<table id="myTable" border="1">
<tr><td>Row1 cell1</td>
<td>Row1 cell2</td></tr>
<tr><td>Row2 cell1</td>
<td>Row2 cell2</td></tr>
<tr><td>Row3 cell1</td>
<td>Row3 cell2</td></tr>
</table><form>
<input type="button" onclick="changeContent()" value="Change content">
</form></body></html>
6 9 2. Write a JavaScript function that creates a table, accept row, column numbers from the user, and input row-column
number as content (e.g. Row-0 Column-0) of a cell.
Sample HTML file :
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Change the content of a cell</title>
<style type="text/css">
body {margin: 30px;}
</style>
</head><body>
<table id="myTable" border="1">
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
</table><form>
<input type="button" onclick="createTable()" value="Create the table">
</form></body></html>
6 9 4. Write a JavaScript program to count and display the items of a dropdown list, in an alert window.
Sample HTML file :
<!DOCTYPE html>
<html><head>
<meta charset=utf-8 />
<style type="text/css">
body {margin: 30px;}
</style>
<title>Count and display items of a dropdown list - InfoMatrix</title>
</head><body><form>
Select your favorite Color :
<select id="mySelect">
<option>Red</option>
<option>Green</option>
<option>Blue</option>
<option>White</option>
</select>
<input type="button" onclick="getOptions()" value="Count and Output all items">
</form></body></html>
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
6 9 5. Write a JavaScript program to calculate the volume of a sphere.
Sample Output of the form :
6 9 6. Write a JavaScript program to display a random image (clicking on a button) from the following list.
Sample Image information :
"http://farm4.staticflickr.com/3691/11268502654_f28f05966c_m.jpg", width: "240", height: "160"
"http://farm1.staticflickr.com/33/45336904_1aef569b30_n.jpg", width: "320", height: "195"
"http://farm6.staticflickr.com/5211/5384592886_80a512e2c9.jpg", width: "500", height: "343"
6 9 7. Write a JavaScript program to highlight the bold words of the following paragraph, on mouse over a certain link.
Sample link and text :
[On mouse over here bold words of the following paragraph will be highlighted]
We have just started this section for the users (beginner to intermediate) who want to work
with various JavaScript problems and write scripts online to test their JavaScript skill.
6 9 8. Write a JavaScript program to get the width and height of the window (any time the window is resized).
7 0 1. Write a JavaScript program to draw two intersecting rectangles, one of which has alpha transparency.
Expected Output :
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
7 0 2. Write a JavaScript program to draw the following right-angled triangle.
Expected Output :
7 0 3. Write a JavaScript program to draw the following diagram [use moveto() function].
Expected Output :
7 0 4. Write a JavaScript program to draw the following diagram [diagonal, white to black circles].
Expected Output :
7 0 6. Write a JavaScript program to delete the rollno property from the following object. Also print the object before or
after deleting the property.
Sample object:
var student = {
name : "David Rayy",
sclass : "VI",
rollno : 12 };
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
7 0 7. Write a JavaScript program to get the length of a JavaScript object.
Sample object :
var student = {
name : "David Rayy",
sclass : "VI",
rollno : 12 };
7 0 8. Write a JavaScript program to display the reading status (i.e. display book name, author name and reading status) of
the following books.
var library = [
{
author: 'Bill Gates',
title: 'The Road Ahead',
readingStatus: true
},
{
author: 'Steve Jobs',
title: 'Walter Isaacson',
readingStatus: true
},
{
author: 'Suzanne Collins',
title: 'Mockingjay: The Final Book of The Hunger Games',
readingStatus: false
}];
7 0 9. Write a JavaScript program to get the volume of a Cylinder with four decimal places using object classes.
Volume of a cylinder : V = πr2 h
where r is the radius and h is the height of the cylinder.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
"14:37:47"
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
["length", "name", "arguments", "caller", "prototype", "isArray", "observe", "unobserve"]
7 1 7. Write a JavaScript function to retrieve all the names of object's own and inherited properties.
7 1 9. Write a JavaScript function to convert an object into a list of `[key, value]` pairs.
7 2 0. Write a JavaScript function to get a copy of the object where the keys have become the values and the values the
keys.
7 2 3. Write a JavaScript function to validate whether a given value type is boolean or not.
7 2 4. Write a JavaScript function to validate whether a given value type is error or not.
7 2 5. Write a JavaScript function to validate whether a given value type is NaN or not.
7 2 6. Write a JavaScript function to validate whether a given value type is null or not.
7 2 9. Write a JavaScript function to validate whether a given value type is pure json object or not.
7 3 1. Write a JavaScript function to validate whether a given value type is char or not.
7 3 2. Write a JavaScript function to check whether given value types are same or not.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
JavaScript Searching and Sorting Algorithm [24 exercises with solution]
7 3 7. Write a JavaScript program to sort a list of elements using the Selection sort algorithm.
The selection sort improves on the bubble sort by making only one exchange for every pass through the list.
7 4 0. Write a JavaScript program to sort a list of elements using Cocktail shaker sort.
Cocktail shaker sort (also known as bidirectional bubble sort, cocktail sort, shaker sort, ripple sort, shuffle sort, or shuttle
sort ) is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort. The algorithm differs from a
bubble sort in that it sorts in both directions on each pass through the list. This sorting algorithm is only marginally more
difficult to implement than a bubble sort, and solves the problem of turtles in bubble sorts. It provides only marginal
performance improvements, and does not improve asymptotic performance; like the bubble sort, it is not of practical
interest,, though it finds some use in education.
7 4 7. Write a JavaScript program to sort an array of numbers, using the bucket sort algorithm.
7 4 8. Write a JavaScript program to sort an array of objects, ordered by properties and orders.
7 4 9. Write a JavaScript program to find the highest index at which a value should be inserted into an array in order to
maintain its sort order, based on a provided iterator function.
7 5 0. Write a JavaScript program to sort an array of objects, ordered by a property, based on the array of orders provided.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com
7 5 2. Write a JavaScript program to find the lowest index at which a value should be inserted into an array in order to
maintain its sorting order, based on the provided iterator function.
7 5 3. Write a JavaScript program to Finds the index of a given element in a sorted array using the binary search algorithm.
7 5 4. Write a JavaScript program to finds the lowest index at which a value should be inserted into an array in order to
maintain its sorting order.
7 5 5. Write a JavaScript program to find the highest index at which a value should be inserted into an array in order to
maintain its sort order.
NYN Arcade, 3rd Floor Lumbini Society, Off. Hitech City Main Rd, Gachibowli, Telangana-500032.
www.the-info-matrix.com