This repository contains a comprehensive set of JavaScript practice problems designed to enhance problem-solving skills in various areas such as Conditional Statements & Loops, Functions, Strings, Arrays, and Objects. These questions are ideal for both beginners and experienced developers, covering common scenarios often encountered in coding interviews and real-world projects.
- Chessboard Pattern: Write a function that prints a chessboard pattern of size
n x nusing loops. - Fibonacci Sequence: Generate the first
nnumbers in the Fibonacci sequence. Implement both iterative and recursive solutions. - Kadane's Algorithm: Write a function that takes an array and returns the largest contiguous subarray sum using Kadane's Algorithm.
- Merge Arrays: Implement a function to merge multiple arrays into one using the spread operator.
- Callback Function: Write an example of a callback function that reads data and processes it asynchronously.
- Reverse a String: Write a function
reverseString(s)that takes a stringsand returns its reverse. - Check if String is Palindrome: Implement a function
isPalindrome(s)to determine if a string reads the same forwards and backwards. - Longest Palindromic Substring: Write a function
longestPalindromicSubstring(s)that finds and returns the longest palindromic substring. - Longest Common Prefix: Create a function
longestCommonPrefix(strs)that takes an array of strings and returns the longest common prefix. - Check Anagram: Implement a function
isAnagram(s, t)to check if two strings are anagrams. - Find All Anagrams in a String: Write a function
findAllAnagrams(s, p)that finds all starting indices ofp's anagrams ins. - Longest Substring Without Repeating Characters: Write a function
lengthOfLongestSubstring(s)to find the longest substring without repeating characters. - String Rotation: Implement a function
isRotation(s1, s2)that checks ifs2is a rotation ofs1. - Valid Parentheses: Write a function
isValid(s)that checks if parentheses in a string are balanced. - String Compression: Write a function
compressString(s)that compresses a string by counting consecutive characters. - Word Break Problem: Write a function
wordBreak(s, wordDict)to determine if a string can be segmented into valid dictionary words. - Substring with Concatenation of All Words: Write a function
findSubstring(s, words)that finds all starting indices of substrings that are concatenations of all words in a list. - Count and Say Problem: Implement the function
countAndSay(n)to generate the nth term of the "count and say" sequence. - Zigzag Conversion: Write a function
convert(s, numRows)that converts a string into a zigzag pattern. - Roman to Integer: Write a function
romanToInt(s)to convert a Roman numeral to an integer. - Integer to Roman: Implement a function
intToRoman(num)to convert an integer to a Roman numeral. - Add Binary Strings: Write a function
addBinary(a, b)that adds two binary strings and returns the sum. - Group Anagrams: Write a function
groupAnagrams(strs)to group anagrams from an array of strings. - Minimum Window Substring: Write a function
minWindow(s, t)that finds the smallest window insthat contains all characters oft. - First Non-Repeating Character: Write a function
firstUniqChar(s)that returns the first non-repeating character in a string.
- Find Missing Number: Given an array of integers from 1 to
N, with one number missing, write a function to find the missing number. - First Non-Repeating Element: Write a function to find the first non-repeating element in an array of integers.
- Merge Two Sorted Arrays: Merge two sorted arrays into one sorted array.
- Move Zeroes: Write a function that moves all zeroes in an array to the end while maintaining the order of other elements.
- Largest and Second Largest: Write a function to find the largest and second-largest elements in an array.
- Check for Duplicates: Write a function that checks if an array contains duplicate elements.
- Maximum Product: Find the maximum product of two integers in an array.
- Kadane’s Algorithm: Write a function to find the subarray with the largest sum.
- Rotate Array: Write a function to rotate an array by
Ksteps. - Sort 0s, 1s, and 2s: Implement the Dutch National Flag problem to sort an array of 0s, 1s, and 2s.
- Find Common Elements: Write a function to find the common elements between two unsorted arrays.
- Two Sum Problem: Write a function to find a pair of integers in an array that sum to a given target.
- Longest Subarray with Zero Sum: Find the length of the longest subarray with a sum of zero.
- Majority Element: Write a function to find the majority element in an array.
- Binary Search: Implement binary search on a sorted array.
- Array Intersection: Write a function to find the intersection of two arrays.
- Minimum Swaps to Sort: Write a function to find the minimum number of swaps required to sort an array.
- Missing Ranges: Write a function to find missing ranges in a sorted array.
- Subarrays Divisible by a Number: Find the number of subarrays with a sum divisible by a given number.
- Kth Largest Element: Write a function to find the kth largest element in an unsorted array.
- Deep Clone: Write a function to deep clone a JavaScript object.
- Merge Objects: Write a function that merges two objects into one.
- Check if Object is Empty: Write a function to check if an object has no properties.
- Object Comparison: Compare two objects to see if they have the same properties and values.
- Group Objects by Property: Write a function to group objects in an array by a specific property.
- Convert Object Keys to Array: Write a function that extracts all keys from an object and returns them in an array.
- Convert Object Values to Array: Write a function that extracts all values from an object and returns them in an array.
- Find Object by Property Value: Write a function to find an object in an array by a specific property value.
- Flatten a Nested Object: Write a function to flatten a deeply nested object.
- Access Nested Properties: Safely access properties in a deeply nested object using optional chaining.
- Count Property Occurrences: Write a function that counts the occurrence of a specific property value in an array of objects.
- Remove Property from Object: Write a function to delete a specific property from an object.
- Check Property Existence: Write a function that checks if a property exists in an object.
- Sort Array of Objects: Write a function to sort an array of objects based on a specific property.
- Freeze Object: Write a function that prevents any modifications to an object.
- Object to Query String: Write a function to convert an object’s properties into a URL query string.
- Dynamic Property Access: Write a function that dynamically accesses an object’s property using variables.
- Array of Objects to Single Object: Write a function that converts an array of objects into a single object using a property as the key.
- Find Max/Min Value in Object: Write a function to find the object with the maximum or minimum value for a specific property.
- Lookup Table: Write a function to convert an array of objects into a lookup table based on a specific property.