AmitDiwan has Published 10744 Articles

Sorting an array of literals using quick sort in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:26:19

386 Views

We are required to write a JavaScript function that takes in an array of numbers and uses the quick sort algorithm to sort it.QuickSort:This algorithm is basically a divide and conquer algorithm where we pick a pivot in every pass of loop and put all the elements smaller than pivot ... Read More

Finding count of special characters in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:24:06

1K+ Views

Let’s say that we have a string that may contain any of the following characters.'!', ", " ,"\'" ,";" ,"\"", ".", "-" ,"?"We are required to write a JavaScript function that takes in a string and count the number of appearances of these characters in the string and return that ... Read More

Checking for the similarity of two 2-D arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:22:13

201 Views

We are required to write a JavaScript function that takes in two 2-D arrays and returns a boolean based on the check whether the arrays are equal or not. The equality of these arrays, in our case, is determined by the equality of corresponding elements.Both the arrays should have same ... Read More

Rotating a 2-D (transposing a matrix) in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:19:12

326 Views

Transpose:The transpose of a matrix (2-D array) is simply a flipped version of the original matrix (2-D array). We can transpose a matrix (2-D array) by switching its rows with its columns.ExampleThe code for this will be −const arr = [    [1, 1, 1],    [2, 2, 2],   ... Read More

Filtering out the non-unique value to appear only once in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:17:46

207 Views

We have an array of literals that contains some duplicate values appearing for many times like this −const arr = [1, 4, 3, 3, 1, 3, 2, 4, 2, 1, 4, 4];We are required to write a JavaScript function that takes in this array and pick out all the duplicate ... Read More

Finding Armstrong numbers in a given range in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:15:40

539 Views

A number is called Armstrong number if the following equation holds true for that number: xy...z =xx +yy+...+zz, where n denotes the number of digits in the number.For example:153 is an Armstrong number because −11 +55 +33 = 1 + 125 + 27 =153We are required to write a JavaScript ... Read More

Sorting arrays using bubble sort in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:13:52

367 Views

We are required to write a JavaScript function that takes in an array of literals and sorts it using bubble sort.ExampleThe code for this will be −const arr = [4, 56, 4, 23, 8, 4, 23, 2, 7, 8, 8, 45]; const swap = (items, firstIndex, secondIndex) => {   ... Read More

Splitting Number into k length array in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:12:13

237 Views

We are required to write a JavaScript function that takes in two numbers say m and k, and returns an array of size k with all the elements of the resulting array adding up to m.ExampleThe code for this will be −const len = 30; const sum = 121; const ... Read More

Checking for special type of Arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:10:17

161 Views

We are required to write a JavaScript function that takes in an array of literals and checks if elements are the same or not if read from front or back. Such arrays are also known by the name of palindrome arrays.Some examples of palindrome arrays are −const arr1 = [‘a’, ... Read More

Merge and remove duplicates in JavaScript Array

AmitDiwan

AmitDiwan

Updated on 15-Oct-2020 09:08:52

390 Views

Suppose, we have two arrays of literals like these −const arr1 = [2, 4, 5, 3, 7, 8, 9]; const arr2 = [1, 4, 5, 2, 3, 7, 6];We are required to write a JavaScript function that takes in two such arrays and returns a new array with all the ... Read More

Advertisements