JavaScript Machine Problems by Myca Joanne M. Faeldonia

Main Machine Problems

Machine Problem 1: ReplaceAll

Replace all occurrences of space with no space.

Machine Problem 2: SearchWord

Check if a word exists in the given sentence.

Machine Problem 3: ReplaceWord

Replace the first occurrence of a word in a sentence.

Machine Problem 4: CountCharacters

Count the number of characters (excluding leading and trailing spaces).

Machine Problem 5: EmailCheck

Check if the input is a valid email (must contain @).

Additional String Problems

Reverse String

Count Words

Capitalize First Letter

Capitalize Each Word

Check Palindrome

Extract First N Characters

Extract Last N Characters

Count Specific Character

Convert Case

Check Starts/Ends With

Find Index of Substring

Repeat String

Pad String

Array Problems

Enter numbers separated by commas (e.g., 1,2,3,4)

Sum of Array

Average of Array

Find Maximum

Find Minimum

Filter Even Numbers

Filter Odd Numbers

Double Each Element

Remove Duplicates

Sort Array Ascending

Sort Array Descending

Number Problems

Check Even or Odd

Check Sign

Factorial

Fibonacci Series

Check Prime

Random Number in Range

String Method Quick Reference

Method Purpose Example
trim() Remove leading/trailing spaces " hi ".trim()"hi"
replace(a, b) Replace first occurrence "aa".replace("a", "b")"ba"
replaceAll(a, b) Replace all occurrences "aa".replaceAll("a", "b")"bb"
includes(s) Check if contains "hello".includes("ell")true
indexOf(s) Find index "hello".indexOf("l")2
length Get length "hello".length5
toUpperCase() Convert to uppercase "hi".toUpperCase()"HI"
toLowerCase() Convert to lowercase "HI".toLowerCase()"hi"
split(sep) Split to array "a,b".split(",")["a","b"]
slice(start, end) Extract portion "hello".slice(0, 2)"he"
charAt(i) Get character at index "hello".charAt(0)"h"
startsWith(s) Check start "hello".startsWith("he")true
endsWith(s) Check end "hello".endsWith("lo")true
repeat(n) Repeat string "hi".repeat(3)"hihihi"
padStart(n, c) Pad start "5".padStart(3, "0")"005"
padEnd(n, c) Pad end "5".padEnd(3, "0")"500"