Sample Data and output: Example: x = 32243; Expected Output: 34223
Write a JavaScript function that accepts a string as a parameter and converts the first letter of each word into upper case.
Example string: 'the quick brown fox' Expected Output: 'The Quick Brown Fox '
Write a JavaScript program to check whether two given integer values are in the range 50..99 (inclusive). Return true if either of them falls within the range.
Write a JavaScript program to compute the sum of the two given integers. If the two values are the same, then return triple their sum
Write a JavaScript program to check a pair of numbers and return true if one of the numbers is 50 or if their sum is 50.
Write a JavaScript function to get all possible subsets with a fixed length (for example 2) combinations in an array.
Sample array : [1, 2, 3] and subset length is 2 Expected output : [[2, 1], [3, 1], [3, 2], ]
Sample arguments : 'abacddbec' Expected output : 'e'
Note : According to wikipedia "Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order".
Sample array: [12, 345, 4, 546, 122, 84, 98, 64, 9, 1, 3223, 455, 23, 234, 213] Expected output: [3223, 546, 455, 345, 234, 213, 122, 98, 84, 64, 23, 12, 9, 4, 1]
Sample object: var student = { name : "David Rayy", sclass : "VI", rollno : 12 };
Sample Output: name,sclass,rollno
Note: The output will come every second.
Expected Console Output: "14:37:42" "14:37:43" "14:37:44" "14:37:45" "14:37:46" "14:37:47".
Write a function that takes a function as its argument and returns a memoized version of the function.
Problem Statement: Implement a memoization function.
Solution Approach: Store the function's results for previous inputs and return the stored result for repeated inputs.
Test Data : - console.log(repeat('Ha!'));
console.log(repeat('Ha!',2));
console.log(repeat('Ha!',3));
Outputs : - "Ha!"
"Ha!Ha!"
"Ha!Ha!Ha! .
Problem Description - Create a string_chop function that takes a string and chop factor(size) and chops out the string into the factor(size) that has been passed
Test Data :
console.log(string_chop('Scaler'));
console.log(string_chop('Scaler',2));
Outputs
["Scaler"]
['Sc' , 'al' ,'er']
Problem Description: Write a JavaScript function named sumArray that takes an array of numbers and returns the sum of all the numbers in the array using the reduce() method.
Inputs:
An array of numbers.
Outputs:
A number representing the sum of the array.
Solution Approach: Initialize the reduce() method with an initial accumulator value of 0. Then, for each value in the array, add it to the accumulator.
Hints: The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
Problem Description:Write a JavaScript function named filterOutOdd that uses the filter() method to filter out odd numbers from an array.
Inputs:
An array of numbers.
Outputs:
An array of numbers without odd numbers.
Hints:Use the filter() method to create a new array with all elements that pass the test implemented by the provided function.
Problem Description: Write a JavaScript function named doubleValues that takes an array of numbers and returns a new array where each number is doubled using the map() method.
Inputs:
An array of numbers.
Outputs:
An array of numbers where each number is doubled.
Hints: The map() method creates a new array with the results of calling a function for every array element.
Problem Description: Write a JavaScript function named allPositive that checks whether all numbers in a given array are positive using the every() method.
Inputs:
An array of numbers.
Outputs:
A boolean value. Return true if all numbers are positive, otherwise false.
Hints: The every() method tests whether all elements in the array pass the test implemented by the provided function.
Solution Approach: Use the every() method and provide a callback that checks if the number is positive
Problem Description: Write a JavaScript function named findFirstNegative that finds and returns the first negative number in an array using the find() method.
Inputs:
An array of numbers.
Outputs:
A number representing the first negative number in the array or undefined if there are no negative numbers.
Hints:The find() method returns the value of the first element in the array that satisfies the provided testing function.
Solution Approach:Use the find() method and provide a callback that checks if the number is negative.
Problem Statement: Write an asynchronous loop function that iterates over an array and performs an asynchronous operation on each element.
Solution Approach: Use async/await within a for...of loop.
Description: The function should take an array and an async function, applying the async function to each element in the array in sequence.
Solution Approach: Recursively compare properties of both objects
Description: Given two objects, the function should return true if they are deeply equal and false otherwise.
Description: Write a function counter that returns a new function on each invocation. The returned function, when called, should increment the counter value and return it.
Problem : Closure Challenge
Solution Approach: Utilize closure to maintain the state of the counter
Description: Implement a debounce function that takes a function and a delay as arguments. The returned function should ensure that the original function is not called more than once in the specified delay.
Solution Approach: Use a timer and clear it on each invocation to delay the function execution.
Description: Write a function getData that returns a Promise. Use this function to fetch data from two different APIs sequentially, and return the combined result. Use any random API that you want
Solution Approach: Utilize the .then method to chain promises.
Description: Write a function calculateTotal that takes an array of numbers, filters out the even numbers, squares the remaining numbers, and then calculates their sum.
Solution Approach: Combine map, filter, and reduce array methods.
Description: Write a generator function range that takes two arguments, start and end, and yields all the numbers in that range.
Solution Approach: Use the function* syntax for generator functions and the yield keyword.
Solution Approach: Use the Proxy object to create a wrapper around another object.
Description:Write a function raceWithTimeout that takes an array of promises and a timeout value. The function should resolve when the first promise resolves or reject if none resolve within the given timeout.
Solution Approach: Use Promise.race and a timeout promise.
Description:Implement a throttle function that ensures a given function is not called more than once in a specified time interval.
Solution Approach: Use a timestamp to track the last invocation time and prevent calling the function if it's within the throttle interval.