Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Problem Can we fit remaining passengers in the bus using JavaScript
ProblemWe are required to write a JavaScript function that takes in three parameters −cap − is the amount of people the bus can hold excluding the driver.on − is the number of people on the bus excluding the driver.wait − is the number of people waiting to get on to the bus excluding the driver.If there is enough space, we should return 0, and if there isn't, we should return the number of passengers we can't take.ExampleFollowing is the code −const cap = 120; const on = 80; const wait = 65; const findCapacity = (cap, on, wait) => { ...
Read MoreFinding astrological signs based on birthdates using JavaScript
ProblemWe are required to write a JavaScript function that takes in a date object. And based on that object our function should return the astrological sign related to that birthdate.ExampleFollowing is the code −const date = new Date(); // as on 2 April 2021 const findSign = (date) => { const days = [21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22]; const signs = ["Aquarius", "Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn"]; let month = date.getMonth(); let day = date.getDate(); if(month == 0 && day
Read MoreLength of shortest unsorted array in JavaScript
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.Our function needs to find the length of one continuous subarray such that if we only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.For example, if the input to the function is −const arr = [3, 7, 5, 9, 11, 10, 16];Then the output should be −const output = 5;Output ExplanationBecause if we sort [7, 5, 9, 11, 10], the whole array will be sorted.ExampleFollowing is the code −const ...
Read MoreTrim tuples by N elements in Python
When it is required to trim a list of tuples by a specific number of elements, the ‘del’ operator can be used.Below is a demonstration of the same −Examplemy_list = [(1, 2, 11), (99, 76, 34, 89), (3.08, 11.56), ("Hi", "Will"), ("Rob", 'Ron')] n = 2 print("The list is :") print(my_list) print("The value of N is") print(n) del my_list[n] print("The list after deleting N elements is :") print(my_list)OutputThe list is : [(1, 2, 11), (99, 76, 34, 89), (3.08, 11.56), ('Hi', 'Will'), ('Rob', 'Ron')] The value of N is 2 The list after deleting N elements is : [(1, 2, ...
Read MoreFinding distance between two points in a 2-D plane using JavaScript
ProblemWe are required to write a JavaScript function that takes in two objects both having x and y property specifying two points in a plane.Our function should find and return the distance between those two points.ExampleFollowing is the code −const a = {x: 5, y: -4}; const b = {x: 8, y: 12}; const distanceBetweenPoints = (a = {}, b = {}) => { let distance = 0; let x1 = a.x, x2 = b.x, y1 = a.y, y2 = b.y; distance = Math.sqrt((x2 - x1) * 2 + (y2 - y1) * 2); return distance; }; console.log(distanceBetweenPoints(a, b));Output6.164414002968976
Read MoreReshaping 2-D array in JavaScript
ProblemWe are required to write a JavaScript function that takes in a 2-D array of numbers, arr, as the first argument and two numbers, r and c, representing the row number and column number of the desired matrix, respectively.Our function should form and return a new 2-D array with the specified rows and columns in the same row-traversing order as they were in the input array.For example, if the input to the function is −const arr = [ [6, 7], [8, 9] ]; const r = 1, c = 4;Then the output should be −const output = [[6, 7, 8, ...
Read MoreString Interpolation in Dart Programming
There are times when we want to make use of variables inside the statement that is made up of string values.We know that we can add two strings together in Dart with the help of the + symbol operator. But to make use of a variable in between the strings that we are concatenating, we need to add one more + symbol and then type the name of the variable, which works okay when it comes to small statements.ExampleConsider the example shown below −void main(){ String name = "Tutorials"; var collegeName = "DTU"; print("Name is " + ...
Read MoreBinary array to corresponding decimal in JavaScript
ProblemWe are required to write a JavaScript function that takes in a binary array (consisting of only 0 and 1).Our function should first join all the bits in the array and then return the decimal number corresponding to that binary.ExampleFollowing is the code −const arr = [1, 0, 1, 1]; const binaryArrayToNumber = arr => { let num = 0; for (let i = 0, exponent = 3; i < arr.length; i++) { if (arr[i]) { num += Math.pow(2, exponent); }; exponent--; }; return num; }; console.log(binaryArrayToNumber(arr));Output11
Read MoreFind and return the longest length of set in JavaScript
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.The array, arr, of length N contains all integers from 0 to N-1. Our function is supposed to find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below.Suppose the first element in S starts with the selection of element A[i] of index = i, the next element in S should be A[A[i]], and then A[A[A[i]]]… By that analogy, we stop adding right before a duplicate element ...
Read MoreRemove Tuples from the List having every element as None in Python
When it is required to remove tuples from a list of tuples where a ‘None’ element is present, a list comprehension can be used.Below is a demonstration of the same −Examplemy_list = [(2, None, 12), (None, None, None), (23, 64), (121, 13), (None, ), (None, 45, 6)] print("The list is : ") print(my_list) my_result = [sub for sub in my_list if not all(elem == None for elem in sub)] print("The None tuples have been removed, the result is : " ) print(my_result)OutputThe list is : [(2, None, 12), (None, None, None), (23, 64), (121, 13), (None, ), ...
Read More