JavaScript Programming
1. How to sort a number Array in ascending order?
Output
2. How to sort a number Array in descending order?
Output
3.How to sort a given array of strings?
Output
4.How to find unique values in an array?
To find unique values in an array we are going to use the array filter method and check if the
value is present using index of method.
Output
5.How to find unique values from an array in sorted order?
We will be using the array filter method first and check if element is present using the index
of and then we will use the sort method to sort the array elements
Output
6.How to find maximum value in a numbered array?
To find maximum value in a numbered array. We are implementing a method which will find
max value.
Inside the method, we are making use of array reduce method and for each element, we will
check if the value is greater than the previous.
Output
7.How to find minimum value in a numbered array?
To find minimum value in a numbered array. We are implementing a method which will find
minimum value.
Inside the method, we are making use of the array reduce method and for each element , we
will check if the value is less than the previous one.
Output
8.How to make a sentence out of a given array?
We need to use Array join method to combine elements from a given array.
Output
9.Given an array of strings reverse each word in the sentence?
We will make use of the string reverse, split and join method to reverse each word in the
sentence.
Output
10.How can you combine two arrays into a third array using
spread operator?
To combine two or more arrays, we will use the spread operator.
Output
11.How do you sort and reverse an array without changing the
original array?
We can use slice () to make copy then reverse () it.
Output
12.How to find duplicate elements in a given array?
To find duplicate in an array, we can make use of the array filter method.
Filter method takes 3 parameters, element, index and array on which filter is applied.
Then we check for the index of each element and return which ever does not match with the
index.
Output
13.Given two strings how can you check if the strings are
anagram for each other?
Anagram is a word, phrase, or name formed by rearranging letters of another, such as cinema
from iceman.
To check if the given strings are anagram or not, we will implement a custom method and
write the logic as given below.
1. First we will make them lowercase
2. Then we will sort the strings
3. And finally we will join them back
4. The only thing then pending will be to compare the string
Output
14.Write a program to find palindrome number or not?
Output
15.Write a program to check given string is palindrome or not?
Output
16.Write a program to find the second largest number in an
array?
Output
17.Write a program to find the second smallest number in an
array?
Output
18.Replace all occurrence of string using built in method?
Output
19.How to split a sentence into array?
We will use string split method to split a string into a Array.
Output
20.How to create an array out of a sentence?
We will use string split method to create an array out of a sentence.
Output
21.Convert a given number into exact decimal points to right
side?
We will use toFixedmethod to convert a given number into exact decimal points
Output
22.How can you combine two objects?
To combine two objects, we will make use of spread operator.
Output
23.How can you uppercase the first character in a string array?
To capitalize the first character of every element in the array we will have to get the first
character using charAt method.
And then apply to UpperCase and finally we will concatenate all the other characters using
substr(1).
Output
24.How can you add an element to an object?
To add an element to an existing object we will use the spread operator.
Output
25.How can you combine two objects?
To combine two objects, we will make use of spread operator.
Output
26.Write a program to generate random number?
Output
27.Write a program to print factorial of a number?
Output
28.Write a program to find given number is odd or even?
Output
29.Write a program that takes a sentence as input and returns
the longest word in it?
Output
30. Write a program an array containing n distinct numbers
taken from 0, 1, 2, ..., n, find the one that is missing from the
array.?
Output
31. Write a program for closure is in JavaScript?
Output