Assignment – 2
1. Write a JavaScript program to find all the index positions of a
given word within a given string.
2. Write a JavaScript program to find the first index of a given
element in an array using the linear search algorithm.
3. Write a JavaScript program to sort a list of elements using Quick
sort.
4. Write a JavaScript program to sort a list of elements using
Merge sort.
5. Write a JavaScript program to sort a list of elements using Heap
sort.
6. Write a JavaScript program to sort a list of elements using
Insertion sort
7. Write a JavaScript program to sort a list of elements using
Bubble sort
8. Write a JavaScript program to sort the characters in a string
alphabetically.
9. Write a JavaScript program to check if a numeric array is sorted
or not.
10. Write a JavaScript function to validate whether a given value
type is null or not.
11. Write a JavaScript function to validate whether a given value is
a number or not.
12. Write a JavaScript function to validate whether a given value is
RegExp or not.
13. 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 };
14. 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
}];
15. Write a JavaScript program to create a clock.
Note: The output will come every second.
Expected Console Output :
"14:37:42"
"14:37:43"
"14:37:44"
"14:37:45"
"14:37:46"
"14:37:47"
16. Write a JavaScript function to parse an URL.
17. Write a JavaScript function to split a string and convert it into an
array of words.
18. Write a JavaScript function that takes a string with both
lowercase and upper case letters as a parameter. It converts upper
case letters to lower case, and lower case letters to upper case.
19. Write a JavaScript function that returns the number of minutes
in hours and minutes.
Input :
[Link](timeConvert(200));
Output :
"200 minutes = 3 hour(s) and 20 minute(s)."
20. Write a JavaScript program to implement a stack that checks if
a given element is present or not in the stack.
21. Write a JavaScript program to check whether a single linked list
is empty or not. Return true otherwise false.
22. Write a JavaScript program to create a class called 'Rectangle'
with properties for width and height. Include two methods to
calculate rectangle area and perimeter. Create an instance of the
'Rectangle' class and calculate its area and perimeter.
23. Write a JavaScript program to create a slideshow that changes
the displayed image when a next or previous button is clicked.
24. Write a JavaScript program that uses a try-catch block to catch
and handle a 'SyntaxError' when parsing an invalid JSON string.
25. Write a JavaScript program to redirect to a specified URL.