-
Reverse Array:
- Write a function
reverseArray(arr)
that takes an array as input and returns a new array with elements in reverse order.
- Write a function
-
Remove Duplicates:
- Create a function
removeDuplicates(arr)
that removes duplicate elements from an array and returns a new array. - Example:
removeDuplicates([1, 2, 2, 3, 4, 4]); // [1, 2, 3, 4]
- Create a function
-
Find Maximum:
- Write a function
findMax(arr)
that returns the largest number in an array. - Example:
findMax([4, 1, 7, 3]); // 7
- Write a function
-
Sum of Elements:
- Implement
sumArray(arr)
to return the sum of all elements in an array. - Example:
sumArray([1, 2, 3]); // 6
- Implement
-
Flatten Nested Arrays:
- Write a function
flattenArray(arr)
that flattens a nested array into a single-level array. - Example:
flattenArray([1, [2, [3, 4]]]); // [1, 2, 3, 4]
- Write a function
-
Merge Two Objects:
- Create a function
mergeObjects(obj1, obj2)
that merges two objects. - Example:
mergeObjects({a: 1}, {b: 2}); // {a: 1, b: 2}
- Create a function
-
Count Properties:
- Write a function
countProperties(obj)
that returns the number of properties in an object. - Example:
countProperties({a: 1, b: 2}); // 2
- Write a function
-
Deep Clone an Object:
- Implement
deepClone(obj)
that creates a deep copy of the given object.
- Implement
-
Filter Object by Keys:
- Write a function
filterByKeys(obj, keys)
that returns a new object containing only the specified keys from the original object. - Example:
filterByKeys({a: 1, b: 2, c: 3}, ['a', 'c']); // {a: 1, c: 3}
- Write a function
-
Swap Keys and Values:
- Write a function
swapKeysAndValues(obj)
that swaps the keys and values of an object. - Example:
swapKeysAndValues({a: 1, b: 2}); // {1: 'a', 2: 'b'}
- Write a function
-
Reverse String:
- Create a function
reverseString(str)
that returns the reversed version of a given string. - Example:
reverseString("hello"); // "olleh"
- Create a function
-
Count Vowels:
- Write a function
countVowels(str)
that counts the number of vowels in a string. - Example:
countVowels("hello world"); // 3
- Write a function
-
Check Palindrome:
- Create a function
isPalindrome(str)
that checks if a string is a palindrome. - Example:
isPalindrome("racecar"); // true
- Create a function
-
Remove Whitespaces:
- Implement
removeWhitespaces(str)
that removes all spaces from a string. - Example:
removeWhitespaces("hello world"); // "helloworld"
- Implement
-
Capitalize Every Word:
- Write a function
capitalizeWords(str)
that capitalizes the first letter of every word in a string. - Example:
capitalizeWords("hello world"); // "Hello World"
- Write a function
-
Predict Output:
- What will be the output of the following code?
console.log(a); var a = 10;
- Explain why.
- What will be the output of the following code?
-
Scope Example:
- Write a function
checkScope()
to demonstrate howlet
,var
, andconst
behave differently inside a block scope.
- Write a function
-
Hoisting of Functions:
- Predict the output:
greet(); function greet() { console.log("Hello!"); }
- Predict the output:
-
Hoisting with
let
andvar
:- Write a short code example showing how
let
andvar
differ in terms of hoisting.
- Write a short code example showing how
-
Temporal Dead Zone:
- Explain the concept of Temporal Dead Zone with an example using
let
andconst
.
- Explain the concept of Temporal Dead Zone with an example using
-
Reassign
let
,var
, andconst
:- Write code that demonstrates reassigning values to
let
,var
, andconst
, and explain the outcomes.
- Write code that demonstrates reassigning values to
-
Variable Shadowing:
- Create an example showing variable shadowing using
let
andvar
.
- Create an example showing variable shadowing using
-
Global Scope vs Local Scope:
- Write code to explain the difference between global and local scopes using
var
,let
, andconst
.
- Write code to explain the difference between global and local scopes using
-
Block Scope with
let
:- Create an example that demonstrates block scoping with
let
.
- Create an example that demonstrates block scoping with
-
Differences between
var
,let
, andconst
:- Write a code snippet that highlights the key differences between these variable declarations.
-
Use
map
to Transform Array:- Write a function
doubleNumbers(nums)
that doubles each number in the array usingmap
. - Example:
doubleNumbers([1, 2, 3]); // [2, 4, 6]
- Write a function
-
Use
filter
to Remove Falsey Values:- Create a function
filterFalsey(arr)
that removes all falsey values from an array usingfilter
. - Example:
filterFalsey([0, 1, false, 2, "", 3]); // [1, 2, 3]
- Create a function
-
Find Object in Array:
- Write a function
findUser(users, name)
that usesfind
to return the user object matching the given name. - Example:
findUser([{name: 'Alice'}, {name: 'Bob'}], 'Bob'); // {name: 'Bob'}
- Write a function
-
Use
reduce
to Sum Array Elements:- Write a function
sumArray(nums)
that returns the sum of numbers in an array usingreduce
. - Example:
sumArray([1, 2, 3, 4]); // 10
- Write a function
-
Check All Even Numbers using
every
:- Write a function
allEven(nums)
that checks if all elements in an array are even usingevery
. - Example:
allEven([2, 4, 6]); // true allEven([1, 2, 3]); // false
- Write a function