AmitDiwan has Published 10744 Articles

Numbers and operands to words in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:57:30

176 Views

ProblemWe are required to write a JavaScript function that takes in a string of some mathematical operation and return its literal wording.ExampleFollowing is the code −const str = '5 - 8'; const convertToWords = (str = '') => {    const o = {       "+" : "Plus", ... Read More

Closest Pair to Kth index element in Tuple using Python

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:56:44

354 Views

When it is required to find the closest pair to the Kth index element in a tuple, the ‘enumerate’ method can be used along with ‘abs’ method.Below is the demonstration of the same −Example Live Demomy_list = [(5, 6), (66, 76), (21, 35), (90, 8), (9, 0)] print("The list is ... Read More

Create a list of tuples from given list having number and its cube in each tuple using Python

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:56:04

885 Views

When it is required to create a list from a given list that have a number and its cube, the list comprehension can be used.Below is the demonstration of the same −Example Live Demomy_list = [32, 54, 47, 89] print("The list is ") print(my_list) my_result = [(val, pow(val, 3)) for ... Read More

Maximum and Minimum K elements in Tuple using Python

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:55:05

1K+ Views

When it is required to find the maximum and minimum K elements in a tuple, the ‘sorted’ method is used to sort the elements, and enumerate over them, and get the first and last elements.Below is the demonstration of the same −Example Live Demomy_tuple = (7, 25, 36, 9, 6, 8) ... Read More

Python program to Find the size of a Tuple

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:54:22

372 Views

When it is required to find the size of a tuple, the ‘sizeof’ method can be used.Below is the demonstration of the same −Example Live Demoimport sys tuple_1 = ("A", 1, "B", 2, "C", 3) tuple_2 = ("Java", "Lee", "Code", "Mark", "John") tuple_3 = ((1, "Bill"), ( 2, "Ant"), (3, "Fox"), ... Read More

Sending personalised messages to user using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:54:04

255 Views

ProblemWe are required to write a JavaScript function that takes in two strings. The first string specifies the user name and second the owner name.If the user and owner are the same our function should return ‘hello master’, otherwise our function should return ‘hello’ appended with the name of that ... Read More

Third smallest number in an array using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:49:26

587 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers of length at least three.Our function should simply return the third smallest number from the array.ExampleFollowing is the code − Live Democonst arr = [6, 7, 3, 8, 2, 9, 4, 5]; const thirdSmallest = () ... Read More

Removing letters to make adjacent pairs different using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:49:04

154 Views

ProblemWe are required to write a JavaScript function that takes in a string that contains only ‘A’, ‘B’ and ‘C’. Our function should find the minimum number of characters needed to be removed from the string so that the characters in each pair of adjacent characters are different.ExampleFollowing is the ... Read More

Counting rings in letters using JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:48:45

198 Views

ProblemWe are required to write a JavaScript function that takes in a string of English alphabets.Our function should count the number of rings present in the string.O', 'b', 'p', 'e', 'A', etc. all have one rings whereas 'B' has 2ExampleFollowing is the code − Live Democonst str = 'some random text ... Read More

Keys associated with Values in Dictionary in Python

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:48:00

424 Views

When it is required to find the keys associated with specific values in a dictionary, the ‘index’ method can be used.Below is the demonstration of the same −Example Live Demomy_dict ={"Hi":100, "there":121, "Mark":189} print("The dictionary is :") print(my_dict) dict_key = list(my_dict.keys()) print("The keys in the dictionary are :") print(dict_key) dict_val ... Read More

Advertisements