AmitDiwan has Published 10740 Articles

Returning the second most frequent character from a string (including spaces) - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:13:24

424 Views

We are required to write a JavaScript function that takes in a string and returns the character which makes second most appearances in the string.ExampleFollowing is the code −const str = 'Hello world, I have never seen such a beautiful weather in the world'; const secondFrequent = str => { ... Read More

Mapping unique characters of string to an array - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:12:26

449 Views

We are required to write a JavaScript function that takes in a string and starts mapping its characters from 0. And every time the function encounters a unique (non-duplicate) character, it should increase the mapping count by 1 otherwise map the same number for duplicate characters.For example − If the ... Read More

Checking semiprime numbers - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:11:12

415 Views

We are required to write a JavaScript function that takes in a number and the function establishes if the provided number is a semiprime or not.SemiprimeA semiprime number is that number which is a special type of composite number that is a product of two prime numbers. For example: 6, ... Read More

Sorting digits of all the number of array - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:10:00

810 Views

We are required to write a JavaScript function that takes in an array of numbers and reorders the digit of all the numbers internally in a specific order (lets say in ascending order for the sake of this problem).For example − If the array is −const arr = [543, 65, ... Read More

Counting the number of redundant characters in a string - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:08:49

299 Views

We are required to write a JavaScript function that takes in a string and returns the count of redundant characters in the string.For example − If the string is −const str = 'abcde'Then the output should be 0If the string is −const str = 'aaacbfsc';Then the output should be 3ExampleFollowing ... Read More

Checking progressive array - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:07:43

223 Views

We are required to write a JavaScript function that takes in an array of strings, ordered by ascending length.The function should return true if, for each pair of consecutive strings, the second string can be formed from the first by adding a single letter either at the beginning or end.For ... Read More

Returning poker pair cards - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:02:15

184 Views

We are required to write a function that takes in an array of exactly five elements representing the five cards of a poker player drawn randomly.If the five cards contain at least one pair, our function should return the card number of the highest pair (trivial if there only exists ... Read More

Finding closed loops in a number - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 09:00:51

625 Views

Other than all being a natural number, the numbers 0, 4, 6, 8, 9 have one more thing in common. All these numbers are formed by or contain at least one closed loop in their shapes.For example, the number 0 is a closed loop, 8 contains two closed loops and ... Read More

Removing last vowel - JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 08:59:33

382 Views

We are required to write a JavaScript function that takes in a string and returns a new string with the last vowel of each word removed.For example − If the string is −const str = 'This is an example string';Then the output should be −const output = 'Ths s n ... Read More

Subtracting two numbers without using the (-) sign JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Sep-2020 08:58:01

350 Views

We are required to write a JavaScript function that takes in two numbers and returns their difference but without using the (-) signExampleFollowing is the code −const num1 = 56; const num = 78; const subtractWithoutMinus = (num1, num2) => {    if(num2 === 0){       return num1;    };    return subtractWithoutMinus(num1 ^ num2, (~num1 & num2)

Advertisements