Q. Write an algorithm that is the integers in range function with recursion.
const intInRangeRecursive = function (startValue, endValue) {
if (endValue - startValue === 2) {
return [startValue + 1];
Q. Write an algorithm that is the factorial function with recursion.
const factorial = function (x) {
if (x === 0) return 1;
else return x * factorial(x-1);
}
Q. Write an algorithm that counts down with recursion.
const countdown = function (n) {
if (n === 0) return;
console.log(n);
countdown(n - 1);
Q. Write an algorithm that performs selection sort on a given array.
let nums = [3, 2, 1];
const selectionSort = function (arr) {
for (let i = 0; i < arr.length - 1; i++) {
let minIndex = i;
Q. Write an algorithm that performs bubble sort on a given array.
const bubbleSort = function (arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++) {
Q. Write an algorithm that performs binary search on a given array. The function will also track, and print out the number of steps required to reach the target of the index of the item.
let testArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 15, 16, 19, 24, 29, 39, 45]
Q. Write an algorithm that performs linear search on a given array.
const linearSearch = function(arr, target) {
for (let i = 0; i < arr.length; i++)…
Q. Create a function that takes an array of numbers and returns a new array, sorted in ascending order (smallest to biggest).
Sort numbers array in ascending order.
Q. Create a function that takes an array of non-negative integers and strings and return a new array without the strings.
const filterArray = function(arr) {
console.log(arr.filter(arr => typeof arr === 'number'));
Q. Write a fucntion that takes an array of integers (positive or negative or both) and return the sum of the absolute value of each element.
const getAbsSum = function(arr) {
let sum = 0;