How To ...
code with JavaScript
[ String | Number | Array | Object
| Set | Map
]
alternate case of each character in a string
for-loop | modulo operator | toLowerCase | toUpperCase
for loop | split | join | toLowerCase | toUpperCase
map | split | join | toLowerCase | toUpperCase
calculate average of array
for loop | length
forEach | length
reduce | length
calculate sum of all numbers in an array
for loop
forEach
recursion | slice | length
reduce
capitalize first letter of each word in an array
for loop | charAt | slice | toUpperCase | toLowerCase
forEach | charAt | slice | toUpperCase | toLowerCase
map | charAt | slice | toUpperCase | toLowerCase
capitalize first letter of each word in a string
for-loop | charAt | slice | split | join | toLowerCase | toUpperCase
map | charAt | slice | split | join | toLowerCase | toUpperCase
regular expression | replace | toLowerCase | toUpperCase
capitalize Nth character in a string
slice | toLowerCase | toUpperCase
check if a string contains another string
includes
indexOf
check if all characters in a string are unique
for loop | object
for-loop | Set
check if number is prime
for loop | modulo operator
for loop | Math.sqrt | modulo operator
check if string is a palindrome
BUILT-IN METHODS | regex | replace | split | reverse | join | toLowerCase
for-loop | regex | replace | length | toLowerCase
check if two strings are anagrams of each other
BUILT-IN METHODS | regex | replace | split | sort | join | length | toLowerCase
CHARACTER FREQUENCY MAP | Object.keys | length | regex | replace | for...of loop | for...in loop
Object | for loop | for...in loop | regEx | replace | length | toLowerCase
compare two arrays for equality
every | length
for loop | length
JSON.stringify
connect to an API
axios | async | await | promise | try | catch | json
axios | then | catch | promise | json
fetch | async | await | promise | try | catch | json
fetch | then | catch | promise | json
xmlHttpRequest | open | onload | status | responseText | onerror | send
convert array elements to upper or lower case
for loop | toLowerCase | toUpperCase
forEach | toLowerCase | toUpperCase
map | toLowerCase | toUpperCase
convert string to camel case
map | split | charAt | slice | join | trim | toLowerCase | toUpperCase
reduce | split | charAt | slice | trim | toLowerCase | toUpperCase
convert string to kebab case
reduce | trim | split | regex | toLowerCase
replace | trim | toLowerCase | regex
convert string to pascal case
map | split | charAt | slice | join | toLowerCase | toUpperCase
reduce | split | charAt | slice | trim | toLowerCase | toUpperCase
convert string to snake case
reduce | trim | split | regex | toLowerCase
replace | regex | trim | toLowerCase
convert string to title case
for loop | split | charAt | slice | join | toLowerCase | toUpperCase
reduce | split | charAt | slice | toLowerCase | toUpperCase
replace | regex | toUpperCase
convert temperature
celsius to fahrenheit and kelvin
fahrenheit to celsius and kelvin
kelvin to celsius and fahrenheit
count frequency of each element in an array
for loop | Object
for...of loop | Object
forEach
reduce
count number of words in a string
filter | trim | split | regex
for...of loop | regular expression | test
for loop | trim | split | length
match | regular expression | length
matchAll | regular expression | Array.from | length
reduce | trim | split | regex
split | trim | regular expression | length
count occurrences of a character in a string
for loop (case-insensitive)
for loop (case-sensitive)
split | length
count odd and even numbers in an array
for loop | modulo operator
forEach | modulo operator
reduce | modulo operator
count vowels in a string
filter | includes | Array.from | length
for loop | toLowerCase
for...of loop | includes | toLowerCase
reduce | includes | Array.from
reduce | indexOf | Array.from
match | regular expression | length
replace | regular expression | length
extract initials from a string
for...of loop | split | charAt | toUpperCase
map | split | charAt | join | toUpperCase
match | regex | join | toUpperCase
find difference between two arrays
filter | includes
for loop | indexOf | push
reduce | indexOf | push
Set | filter | has
Set | difference
find factorial of a number
for loop
recursion
while loop
find first non-repeated character in a string
find | indexOf | lastIndexOf
for loop | indexOf | lastIndexOf
for loop | slice | includes | charAt
for...of loop | Map | set | get
for...of loop | object
find intersection of two arrays
filter | includes
forEach | includes | push
reduce | includes | push
Set | for...of loop | has | push
Set | intersection
find longest word in a string
for...of loop | split | length
reduce | split | length
sort | split | length
find maximum difference between two numbers in an array
for loop
for loop | Math.max | Math.min
Math.max | Math.min
nested for loops | Math.abs
reduce | Math.max | Math.min
find maximum number in an array
for loop
reduce
sort
find minimum and maximum number in an array
for loop
sort
find minimum number in an array
for loop
reduce
sort
find Nth maximum number in an array
sort - [duplicates allowed]
sort | Set - [duplicates removed]
find Nth minimum number in an array
sort - [duplicates allowed]
sort | Set - [duplicates removed]
find power of number
exponentiation operator
for loop
Math.pow
recursion
find Nth root of number
exponentiation operator
Math.pow
find symmetric difference between two arrays
filter | includes
reduce | indexOf | push
Set | filter | has
Set | for...of loop | has | push
Set | symmetricDifference
find union of two arrays
concat | filter | indexOf
reduce | concat | includes | push
Set | spread syntax
Set | push
Set | union
generate countdown
promise | async | await | resolve | setInterval | clearInterval
promise | resolve | setInterval | clearInterval
recursion | setTimeout
setInterval | clearInterval
generate fibonacci sequence up to n terms
for loop | slice - [ return as an array ]
for loop - [ print to console ]
recursion | for loop - [ print to console ]
while loop | slice - [ return as an array ]
while loop - [ print to console ]
generate lottery numbers
Set | size | add | while loop | Math.random | Math.floor | Array.from | sort
generate pattern
CHESS BOARD PATTERN | for loop | modulo operator
TRIANGLE PATTERN | for loop
generate random color
hex | for loop | Math.random | Math.floor
hex | Math.random | Math.floor | toString | padStart
hex | Math.random | Math.floor | toString | slice
hsl | Math.random | Math.floor
rgb | Math.random | Math.floor
generate random numbers
Math.random | Math.floor | Math.ceil
inverse case of a string
for loop | toLowerCase | toUpperCase
for loop | charCodeAt | fromCharCode | toLowerCase | toUpperCase
merge two or more arrays
concat
push
spread syntax
merge two arrays with alternative values
for loop | push | Math.max | length
reduce | push | concat | slice | length
while loop | push | length
remove duplicates from an array
filter | indexOf
for loop | includes | push
forEach | includes | push
reduce | includes
reduce | indexOf | push
Set
remove falsy values from an array
filter | Boolean
for loop | push
repeat a string
for loop
Array | join
recursion
repeat
while-loop
reverse a string
split | reverse | join
for loop
for...of loop
forEach | split
recursion | substring | charAt
reduce | split
DECREMENTING WHILE LOOP | while loop
TWO POINTER METHOD | while loop | split | join
reverse order of words in a string
BUILT-IN METHODS | split | reverse | join
for loop | split | trim
reduce | split | trim
solve FizzBuzz problem
for loop | modulo operator | push - [ return as an array ]
for loop | modulo operator - [ print to console ]
recursion | modulus operator | length | push | join - [ return as an array ]
switch | for-loop | modulo operator - [ print to console ]
for-loop | modulo operator | ternary operator - [ print to console ]
while-loop | modulo operator - [ print to console ]
FizzBuzz with user inputs | for loop - [ print to console ]
solve the two sum problem
BRUTE FORCE SOLUTION | nested for loops
HASH MAP SOLUTION | Map | has | get | set | for loop
TWO POINTER SOLUTION | map | sort | while loop | length
sort an array
BUBBLE SORT | for loop
BUBBLE SORT | while loop | for loop
BUILT-IN SORT | sort numbers | sort | slice
BUILT-IN SORT | sort strings | sort | slice | localeCompare | toLowerCase
BUILT-IN SORT | sort numbers & strings | sort | slice | localeCompare
INSERTION SORT | for loop | while loop
MERGE SORT | recursion | while loop | slice | push | Math.floor | concat | length
QUICK SORT | recursion | for loop | push
SELECTION SORT | nested for loops
⇑