ASMJavaScriptCoding4ExperiencedSet1

 




Java Script Coding Assignment 4 Experienced

 

1.       How can you count the number of occurrences of a particular character in a JavaScript String, and what are some different approaches that can be used to achieve this?

 

2.       What is a possible approach to find the most frequently occurring character in a JavaScript

String, and how can you implement this solution in JavaScript programming?

 

3.       What is an approach to add the individual digits of a given integer in JavaScript programming, and how can you implement this solution to calculate the sum of digits for an integer such as 567 and return the result of 9?

 

4.       Write a JavaScript program to find the largest subarray in an integer array that has a sum of 0. Can you explain your approach to solving this problem and provide a step-by-step explanation of your code? How does your program handle edge cases, such as when there is no subarray with a sum of 0 or when the input array is empty?

Eg: Input = { 3, 4, -7, 3, 1, 3, 1, -4, -2, -2 }

{ 3, 4, -7 }

{ 4, -7, 3 }

{ -7, 3, 1, 3 }

{ 3, 1, -4 }

{ 3, 1, 3, 1, -4, -2, -2 }

{ 3, 4, -7, 3, 1, 3, 1, -4, -2, -2 } // This should be the output

 

5.       Can you provide a program in JavaScript that finds all the subarrays in an array whose sum is

Zero?  How does your implementation work? Can you explain the time and space complexity of your solution? Are there any optimizations that can be made to improve the efficiency of your program?

 

6.       Write a JavaScript program to find the sum of all the numbers in a given string. For example, if the input string is "1ab2d4hj6", the program should output the sum of numbers in the string, which is 13. The program should take a string as input from the user and use regular expressions to extract all the numbers from the string. It should then iterate over the extracted numbers and add them up to get the final sum. If there are no numbers in the string, the program should output 0.

 

7.       Write a JavaScript program that takes two strings as input and finds the number of occurrences of the second string in the first string.

Example:

Input:

String 1: "hello world"

String 2: "l"

Output:

Number of occurrences of "l" in "hello world" is 3

 

8.       Write a JavaScript program to find the sum of all the numbers in a given string. Your program should take a string as input from the user and then find all the numbers in the string. It should then add up all the numbers and print the sum to the console. Here are some requirements for your program:

·         The string should be read from the console using the Scanner class.

·         Your program should use regular expressions to find all the numbers in the string.

·         The sum of the numbers should be calculated using a loop.

·         If there are no numbers in the string, your program should print a message saying so.

 

Example:

Input: "Hello 123 world 456"

Output: 579

Write test cases on the same program by using the assertion method in Junit.

 

9.       Write a JavaScript program to find the sum of all the numerical digits in a given string s1. The

string can contain alphabets and digits in any order, but the digits are guaranteed to be consecutive. Your program should output the total sum of all the digits in the string.

For example, given the string s1 = "abc4ui78fg95", the program should output sum = 177, since

the digits in the string are 4, 7, 8, 9, and 5, and their sum is 4 + 7 + 8 + 9 + 5 = 33.

 

10.   Given a matrix of integers, write a program to modify the matrix such that if any element of the matrix is 0, then the entire row and column of that element should be set to 0. Implement this program using JavaScript. The program should take the following input:

·         The matrix, represented as a two-dimensional array of integers.

·         The program should perform the following tasks:

·         Check for the presence of 0 in the matrix and record the positions of the 0 elements.

·         Modify the matrix by setting the entire row and column to 0 if any element in the row or column contains a 0.

·         The program should return the modified matrix as output.

For example, given the matrix:

{ 1, 2, 3 }

{ 4, 0, 6 }

{ 7, 8, 9 }

The program should modify the matrix to:

{ 1, 0, 3 }

{ 0, 0, 0 }

{ 7, 0, 9 }

And return the modified matrix as output.

 

11.   Write a JavaScript program to find all the duplicate elements in an integer array with less time complexity.

Example input:

int[] arr = {4, 2, 4, 5, 2, 3, 1, 1, 6, 7, 7};

Expected output:

Duplicate elements in the given array are:   4 2 1 7

Constraints:

·         The input array can have a maximum of 10^5 elements.

·         The program should have a time complexity of O(n), where n is the size of the input array.

 

12.   Write a JavaScript program to reverse an array without using any inbuilt methods.

 

13.   Write a SQL query to fetch department details for a given employee ID?

 

 

14.   Write a JavaScript program to display the highest prime number.

 

15.   Program to find the largest number in a given input array and replace it with a given number/string.

 

16.   In an array take alternative numbers and reverse them. Put it again in the place of array again

e.g., arr = [1,2,3,4,5,6,7,8]

newarr = [1,8,3,6,5,4,7,2]

 

17.   Given an unsorted array a = [3,1,5,2,7], find alternate elements "3,5,7", reverse them "7,5,3"

and place them in the original array

·         Expected result [7,1,5,2,3]

 

18.   Find second largest number [3,1,5,2,7]

 

19.   Out of given 3 arrays with n number of elements, find out the common element(s) for all 3

arrays.

 

20.   From a given array, make n elements rotate. eg. given Array:[21,54,11,35,4,18], index:3; output Array: [4,18,21,54,11,35]

 

21.   From an array, find out the elements, and their repetition and print as element=count.

eg.

Input Array: [2,1,3,4,6,5,4,7,5,6,8,2,3,6,2,6,4,4,7,3,4,5,6]

Output:

2=3

1=1

3=3

4=5

6=5

5=5

7=2

8=1

 

22.   Print the right diagonal of the matrix

Input:

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

 

Output:

4 7 10 13

 

23.   String= "abaade", search for a character "a" in the given string and return its occurrence.

 

24.   How will you remove duplicate elements from an array?

 

25.   Can you provide a sample program in JavaScript that takes an array as input and generates a new array containing only unique elements, and explain how it works in detail?

26.   How can you extract all the keys from a nested object in JavaScript, given an object 'object = {id:1 , address : {'primaryAddress':'abc'} }', and return an array of keys as

'['id','address','primaryAddress']'? Also, how would you remove duplicates from an array

'[1,1,2,2,3,4,4,5]' in JavaScript?

 

27.   Write a JavaScript function that takes an array of numbers as input and returns a new array

where each element at index i is the sum of all the elements in the input array up to index i. For

example, if the input array is [1, 2, 3, 4], the output should be [1, 3, 6, 10].

 

28.   Given an array of strings, write a JavaScript function that returns the longest string from the

array. For example, if the input array is ["i am in pune", "i am in hyderabad", "location"], the output

should be "i am in hyderabad".

 

29.   Write a program that finds the longest string in an array and returns the number of words in

that string. The input array will be of the form:

const sentences = ["alice and bob love leetcode", "i think so too", "this is great thanks very

much"];

 

The program should output the longest sentence along with the number of words in that

sentence. Additionally, write a program that takes an input array of numbers and returns an output array where the first element of the output array is the first element from the input array, the second element of the output array is the sum of the first and second elements from the input array, the third element of the output array is the sum of the previous element (1 + 2 = 3) and the next

element (3 + 3 = 6), and the fourth element is the sum of the previous element (3 + 3 = 6) and

the next element (6 + 4 = 10).

 The input array will be of the form:

const inputArray = [1, 2, 3, 4];

The program should output an array of the form:

outputArray = [1, 3, 6, 10];

 

30.   Reverse a String: Write a function to reverse a string in JavaScript.

31.   Palindrome Checker: Create a function to check if a given string is a palindrome.

32.   Factorial Calculation: Write a function to calculate the factorial of a number.

33.   Fibonacci Sequence: Implement a function to generate the nth number in the Fibonacci sequence.

34.   Sum of Array Elements: Create a function to calculate the sum of all elements in an array.

35.   Largest Number in Array: Find the largest number in an array.

36.   Smallest Number in Array: Find the smallest number in an array.

37.   Remove Duplicates: Write a function to remove duplicates from an array.

38.   Array Intersection: Find the intersection of two arrays.

39.   Array Union: Find the union of two arrays.

40.   Object Key Count: Write a function to count the number of keys in an object.

41.   Object Deep Clone: Implement a function to create a deep clone of an object.

42.   Array Sorting: Sort an array of objects based on a specific property.

43.   Array Filtering: Filter an array of objects based on a condition.

44.   Callback Functions: Write a function that takes a callback and calls it.

45.   Asynchronous Callbacks: Handle asynchronous operations using callbacks.

46.   Promises: Implement a promise to handle asynchronous operations.

47.   Promise Chain: Chain multiple promises together.

48.   Async/Await: Rewrite asynchronous code using async/await.

49.   Error Handling with Promises: Handle errors using promises.

50.   Ajax Request: Make an HTTP request using XMLHttpRequest.

51.   Fetch API: Make an HTTP request using the Fetch API.

52.   Promise.all: Use Promise.all to handle multiple asynchronous requests.

53.   Local Storage: Store and retrieve data from the browser's local storage.

54.   DOM Manipulation: Create, modify, and delete DOM elements.

55.   Event Handling: Handle DOM events using JavaScript.

56.   Form Validation: Validate a form using JavaScript.

57.   Timer Functions: Implement a countdown timer.

58.   Drag and Drop: Create a drag-and-drop interface.

59.   Cookies: Set and retrieve cookies in JavaScript.

60.   Regular Expressions: Use regular expressions for pattern matching.

61.   JSON Parsing: Parse and stringify JSON data.

62.   Web Workers: Implement a simple web worker.

63.   Closures: Demonstrate the concept of closures in JavaScript.

64.   Prototype Inheritance: Explore prototype-based inheritance.

65.   Classes: Define and use classes in JavaScript.

66.   Module System: Use ES6 modules to organize code.

67.   Functional Programming: Implement map, filter, and reduce functions.

68.   Recursion: Solve a problem using recursion.

69.   Binary Search: Implement a binary search algorithm.

70.   Graph Traversal: Traverse a graph using depth-first or breadth-first search.

71.   Linked List: Create a linked list and perform operations on it.

72.   Tree Structure: Work with binary trees or other tree structures.

73.   Memoization: Optimize a recursive function using memoization.

74.   Promises vs. Callbacks: Explain the differences and use cases.

75.   Async Patterns: Compare async patterns (callbacks, promises, async/await).

76.   Error Handling: Handle errors in asynchronous code effectively.

77.   REST API Consumption: Fetch and display data from a REST API.

78.   State Management: Implement state management for a web application.

79.   Form Handling: Build a dynamic form with validation.

80.   Real-time Updates: Implement real-time updates using WebSockets.

81.   Authentication: Implement user authentication in a web app.

82.   Testing with Jest: Write unit tests for JavaScript code using Jest.

83.   Responsive Design: Create a responsive design using CSS and media queries.

84.   Cross-Browser Compatibility: Ensure compatibility with different browsers.

85.   SEO Optimization: Optimize a website for search engines.

86.   Performance Optimization: Improve website performance.

87.   Security: Implement security best practices in web development.

88.   Code Minification: Minify and bundle JavaScript code.

89.   Error Logging: Implement client-side error logging.

90.   Local File Handling: Read and write local files using JavaScript.

91.   Geolocation: Access and use the user's geolocation.

92.   Canvas Drawing: Create drawings and animations using the HTML5 canvas.

93.   Audio/Video Playback: Embed and control audio and video elements.

94.   Custom Events: Create and dispatch custom events in the DOM.

95.   Image Carousel: Create an image carousel or slideshow using JavaScript.

96.   Image Gallery Filter: Build an image gallery with category filters.

97.   Infinite Scroll: Implement infinite scrolling for a long list of items.

98.   Web Scraping: Write a script to scrape data from a website (note the legality and ethical considerations).

99.   Map Integration: Integrate a map (e.g., Google Maps) into a web application and add markers with custom data.

100.                        Weather App: Build a weather application that fetches and displays weather information for a given location using a public weather API.


Comments

Popular posts from this blog

FrontEnd - FAQs - Part 1

Java Script - FAQs

CoreJava - ClassesObjectsMethods - Assignment