JavaScript Programming
1. How to sort a number Array in ascending order?
Output
2. How to sort a number Array in descending order?
Output
[Link] to sort a given array of strings?
Output
[Link] 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
[Link] 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
[Link] 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
[Link] 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
[Link] to make a sentence out of a given array?
We need to use Array join method to combine elements from a given array.
Output
[Link] 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
[Link] 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
[Link] do you sort and reverse an array without changing the
original array?
We can use slice () to make copy then reverse () it.
Output
[Link] 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
[Link] 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
[Link] a program to find palindrome number or not?
Output
[Link] a program to check given string is palindrome or not?
Output
[Link] a program to find the second largest number in an
array?
Output
[Link] a program to find the second smallest number in an
array?
Output
[Link] all occurrence of string using built in method?
Output
[Link] to split a sentence into array?
We will use string split method to split a string into a Array.
Output
[Link] to create an array out of a sentence?
We will use string split method to create an array out of a sentence.
Output
[Link] a given number into exact decimal points to right
side?
We will use toFixedmethod to convert a given number into exact decimal points
Output
[Link] can you combine two objects?
To combine two objects, we will make use of spread operator.
Output
[Link] 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
[Link] can you add an element to an object?
To add an element to an existing object we will use the spread operator.
Output
[Link] can you combine two objects?
To combine two objects, we will make use of spread operator.
Output
[Link] a program to generate random number?
Output
[Link] a program to print factorial of a number?
Output
[Link] a program to find given number is odd or even?
Output
[Link] 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