This repository contains a collection of fundamental JavaScript programs covering various programming concepts and algorithms. Each file demonstrates a specific programming problem solution.
Checks if a given number is an Armstrong number.
- Description: An Armstrong number is a number where the sum of its digits each raised to the power of the number of digits equals the number itself.
- Example:
153 = 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 - Features:
- Counts digits in the number
- Calculates power of each digit
- Compares sum with original number
Calculates the factorial of a given number.
- Description: Computes the product of all positive integers up to a given number.
- Example:
5! = 5 × 4 × 3 × 2 × 1 = 120 - Implementation: Uses a for loop to multiply numbers iteratively
Checks if a given number is a prime number.
- Description: Determines whether a number is only divisible by 1 and itself.
- Implementation: Checks divisibility from 2 up to the number
Checks if a given number is a Strong number.
- Description: A Strong number is a number where the sum of factorials of its digits equals the number itself.
- Example:
145 = 1! + 4! + 5! = 1 + 24 + 120 = 145 - Features:
- Extracts each digit
- Calculates factorial for each digit
- Sums factorials and compares with original number
Checks if a number is even or odd.
- Description: Determines whether a number is divisible by 2 (even) or not (odd).
- Implementation: Uses modulo operator (
%) to check remainder
Reverses a given number.
- Description: Reverses the digits of a number (e.g., 123 becomes 321).
- Implementation: Uses modulo and division operations to extract and reverse digits
Reverses a given string.
- Description: Reverses the characters in a string.
- Implementation:
- Using for loop (iterates from end to start)
- Using while loop (alternative approach)
Checks if a string is a palindrome.
- Description: Determines if a string reads the same forwards and backwards.
- Example: "kayak" is a palindrome
- Implementation: Reverses string and compares with original
Replaces spaces with underscores and converts to lowercase.
- Description: Converts a string with spaces to snake_case format.
- Example: "Hello World This Is Js" → "hello_world_this_is_js"
- Features:
- Splits string by spaces
- Converts to lowercase
- Joins with underscores
Replaces underscores with spaces and capitalizes each word.
- Description: Converts snake_case to Title Case.
- Example: "hello_world_this_is_js" → "Hello World This Is Js"
- Features:
- Splits by underscores
- Capitalizes first letter of each word
- Joins with spaces
Counts occurrences of words and characters.
- Description: Multiple counting operations:
- Count repeated words in a string
- Count words in an array of strings
- Count occurrence of characters in a string
- Count occurrences by property in an array of objects
- Examples:
- Word count:
"hello world hello"→{ 'hello': 2, 'world': 1 } - Character count:
"hello"→{ 'h': 1, 'e': 1, 'l': 2, 'o': 1 }
- Word count:
Checks if a number is a palindrome.
- Description: Determines if a number reads the same forwards and backwards.
- Example:
121is a palindrome number - Implementation: Reverses the number and compares with original
Counts repeated numbers in an array.
- Description: Counts how many times each number appears in an array.
- Example:
[5,5,5,5,8,8,9]→{ '5': 4, '8': 2, '9': 1 } - Implementation: Uses object to track occurrences
Finds missing numbers from an array.
- Description: Identifies numbers missing from a sequence 1 to N.
- Example: Array
[1,2,3,5]with count 10 → Missing:[4,6,7,8,9,10] - Features:
- Checks if each number from 1 to count exists in array
- Returns array of missing numbers
Generates Fibonacci series.
- Description: Generates the Fibonacci sequence where each number is the sum of the two preceding ones.
- Sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... - Implementation:
- Using for loop
- Using while loop
- Node.js installed on your system
Each file can be run independently using Node.js:
node filename.jsnode ArmstrongNo.js
# Output: 153 is Armstong No- All programs are standalone and can be executed independently
- Programs contain example input values that can be modified
- Some programs include comments explaining the logic
- Code follows basic JavaScript syntax and practices
- Number Theory: Armstrong numbers, Prime numbers, Strong numbers, Factorials
- String Manipulation: Reversing, Palindrome checking, Case conversion
- Array Operations: Counting, Finding missing numbers
- Series Generation: Fibonacci series
- Basic Operations: Even/Odd checking, Number reversing
These programs cover:
- Loops (for, while)
- Conditional statements (if/else)
- Array manipulation methods
- String manipulation methods
- Mathematical operations
- Object creation and manipulation
- Algorithm implementation
- Modify the input variables at the top of each file to test with different values
- Use console.log outputs to understand the program flow
- Experiment with different input types to see edge cases
- Combine concepts from different files to solve more complex problems
This repository contains basic programming examples for educational purposes.