JavaScript Examples



JavaScript is the most popular programming language in the world, making it a programmer's great choice. Once you learn JavaScript, it helps you develop great front-end and back-end software using different JavaScript based frameworks like ReactJS, jQuery, Node.JS, etc.

These JavaScript examples are organized by topics and arranged from easy to difficult questions. Solving questions based on these topics will help improve your JavaScript problem-solving capabilities. We recommend that you try solving each problem before checking its solution.

Table of Content

Basic Mathematics and Geometry Examples

This section deals with fundamental mathematical examples and geometric calculations. It includes problems like calculating areas, perimeters, distances, angles, and basic arithmetic examples. Examples include finding the area of different shapes, implementing geometric algorithms like point-in-polygon, and solving basic math word problems programmatically.

Problem Solve Solution
Find Area of a Circle
Find Area and Perimeter of Rectangle
Find Perimeter of a Triangle
Find Simple Interest
Convert Radians to Degree
Check Whether a Given Number is Power of 2

Array and Algorithm Examples

This focuses on manipulating one-dimensional arrays or lists. Common problems include sorting, searching, rotating arrays, finding subarray with specific properties, and implementing array-based algorithms. Questions often cover concepts like binary search, two-pointer technique, sliding window, and array transformations.

Problem Solve Solution
Find Closest Number in Array
Find the Lost Element From a Duplicated Array
Two Pointers Technique
Count Pairs with Given Sum
Equilibrium Index of an Array
Counting Frequencies of Array Elements
Third Largest Element in an Array of Distinct Elements
Find k Maximum Elements of Array in Original Order
Block Swap Algorithm for Array Rotation
Number of Local Extrema in an Array
Cyclically Rotate an Array by One
Find Common Elements in Two Sorted Arrays
Find k Pairs with Smallest Sums in Two Arrays

Matrix Examples

These questions involve 2D arrays or matrices. Topics include matrix multiplication, transposition, rotation, spiral traversal, and finding patterns in matrices. Problems often require understanding of nested loops and 2D array indexing. Matrix-based mathematical examples and transformations are common themes.

Problem Solve Solution
Check if a Matrix is Symmetric
Find Difference Between Sums of Two Diagonals
Check if Matrix is Upper Triangular
Maximum and Minimum in a Square Matrix
Counting Sets of 1s and 0s in a Binary Matrix
Diagonally Dominant Matrix
Mirror of Matrix Across Diagonal
Rotate a Matrix by 180 Degrees
Check if a Given Matrix is Sparse or Not
Efficiently Compute Sums of Diagonals of a Matrix
Form Coils in a Matrix
Frequencies of Even and Odd Numbers in a Matrix

Linked List Examples

This section covers examples on singly and doubly linked lists. Problems include list traversal, insertion, deletion, merging, reversing, and detecting cycles. Questions often test understanding of pointer manipulation, memory management, and implementing common linked list algorithms like finding the middle node or detecting intersections.

Problem Solve Solution
Inserting a Node in a Linked List
Searching an Element in a Linked List
Finding Length of a Linked List
Merging Two Sorted Linked Lists in Reverse Order
Clockwise Rotation of Linked List
Reversing a Linked List in Groups of Given Size
Swapping Nodes in a Linked List Without Swapping Data
Delete Nodes Which Have a Greater Value on Right Side

String Manipulation & Pattern Matching Examples

These problems focus on processing and analyzing text strings. Common tasks include string searching, substring examples, pattern matching, palindrome detection, and string transformations. Questions often involve regex, string algorithms like KMP or Boyer-Moore, and character manipulation.

Problem Solve Solution
Left Rotation and Right Rotation of a String
Check if Strings are Rotations of Each Other or Not
Check if a String Can Be Formed From Another String by at Most X Circular Clockwise Shifts
Check if a String Can Be Obtained by Rotating Another String by 2 Places
Find Lexicographically Minimum String Rotation
Find Longest Common Prefix Using Word by Word Matching

Time & Date Examples

This section deals with datetime calculations and manipulations. Problems include date arithmetic, formatting, timezone conversions, calculating time differences, and working with calendar-based algorithms. Questions often test understanding of datetime libraries and handling edge cases like leap years.

Problem Solve Solution
Check if a Given Year is Leap Year
Convert 24 Hours Format to 12 Hours

Browser & System Examples

These questions focus on browser APIs and system-level examples. Topics include DOM manipulation, event handling, file examples, network requests, and working with browser storage. Problems often test understanding of asynchronous programming and browser/system interfaces.

Problem Solve Solution
Retrieve Client's IP Address
Access Browsing History

Number Theory & Counting Examples

This section covers mathematical concepts like prime numbers, factors, multiples, and combinatorics. Problems include implementing algorithms for prime factorization, finding GCD/LCM, calculating combinations/permutations, and solving number sequence problems.

Problem Solve Solution
Count Primes in Ranges
Convert Positive Integers to Roman Numbers
Count Rotations Divisible by 4
Count Rotations Divisible by 8
Count Rotations Which are Divisible by 10
Generate All Rotations of a Number

Object & Array Manipulation Examples

These problems focus on working with complex data structures combining objects and arrays. Common tasks include deep cloning, merging objects, filtering/mapping nested structures, and implementing data transformations. Questions often test understanding of reference types and immutable examples.

Problem Solve Solution
Merge Two Objects into a Single Object and Adds the Values for Same Keys
Find if There is a Subarray with 0 Sum
The Least Frequent Element in an Array
The Last Duplicate Element in a Sorted Array
Count 1's in a Sorted Binary Array
Advertisements