Articles on Trending Technologies

Technical articles with clear explanations and examples

Remove Tuples from the List having every element as None in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 436 Views

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

Converting km per hour to cm per second using JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 733 Views

ProblemWe are required to write a JavaScript function that takes in a number that specifies speed in kmph and it should return the equivalent speed in cm/s.ExampleFollowing is the code −const kmph = 12; const convertSpeed = (kmph) => {    const secsInHour = 3600;    const centimetersInKilometers = 100000;    const speed = Math.floor((kmph * centimetersInKilometers) / secsInHour);    return `Equivalent in cmps is: ${speed}`; }; console.log(convertSpeed(kmph));OutputEquivalent in cmps is: 333

Read More

Inverting signs of integers in an array using JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 270 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers (negatives and positives).Our function should convert all positives to negatives and all negatives to positives and return the resulting array.ExampleFollowing is the code −const arr = [5, 67, -4, 3, -45, -23, 67, 0]; const invertSigns = (arr = []) => {    const res = [];    for(let i = 0; i < arr.length; i++){       const el = arr[i];       if(+el && el !== 0){          const inverted = el * -1;          res.push(inverted);       }else{          res.push(el);       };    };    return res; }; console.log(invertSigns(arr));Output[ -5, -67, 4, -3, 45, 23, -67, 0 ]

Read More

Super constructor in Dart Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 752 Views

The subclass can inherit the superclass methods and variables, but it cannot inherit the superclass constructor. The superclass constructor can only be invoked with the use of the super() constructor.The super() constructor allows a subclass constructor to explicitly call the no arguments and parametrized constructor of superclass.SyntaxSubclassconstructor():super(){ }Though, it is not even necessary to use the super() keyword as the compiler automatically or implicitly does the same for us.When an object of a new class is created by making use of the new keyword, it invokes the subclass constructor which implicitly invokes the parent class's default constructor.Let's make use of an example where ...

Read More

divisibleBy() function over array in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 188 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers and a single number as two arguments.Our function should filter the array to contain only those numbers that are divisible by the number provided as second argument and return the filtered array.ExampleFollowing is the code −const arr = [56, 33, 2, 4, 9, 78, 12, 18]; const num = 3; const divisibleBy = (arr = [], num = 1) => {    const canDivide = (a, b) => a % b === 0;    const res = arr.filter(el => {       return canDivide(el, num);    });    return res; }; console.log(divisibleBy(arr, num));Output[ 33, 9, 78, 12, 18 ]

Read More

Finding minimum time difference in an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 456 Views

ProblemWe are required to write a JavaScript function that takes in an array of 24-hour clock time points in "Hour:Minutes" format. Our function should find the minimum minutes difference between any two time points in the array.For example, if the input to the function is −const arr = ["23:59", "00:00"];Then the output should be −const output = 1;Because the minimum difference between the times is 1 minuteExampleFollowing is the code −const arr = ["23:59", "00:00"]; const findMinDifference = (arr = []) => {    const find = (str = '') => str.split(':').map(time => parseInt(time, 10))    const mapped = arr.map((time) ...

Read More

Super keyword in Dart Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 782 Views

Super keyword in dart is used to refer to the parent's class object's methods or variables. In simple terms, it is used to refer to the superclass properties and methods.The most important use of the super keyword is to remove the ambiguity between superclass and subclass that have methods and variables with the same name.The super keyword is able to invoke the parent's objects method and fields, as when we create an instance of the subclass in Dart, an instance of the parent class is also created implicitly.Syntaxsuper.varName or super.methodNameAs we can access both the variables and methods of the parent's ...

Read More

Implementing partial sum over an array using JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 402 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should construct and return a new array in which each corresponding element is the sum of all the elements right to it (including it) in the input array.ExampleFollowing is the code −const arr = [5, 6, 1, 3, 8, 11]; const partialSum = (arr = []) => {    let sum = arr.reduce((acc, val) => acc + val);    const res = [];    let x = 0;    if(arr.length === 0){       return [0];    }    for(let i = 0; i

Read More

Creating a chained operation class in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 149 Views

ProblemWe are supposed to create a user defined data type Streak in JavaScript that can be chained to any extent with value and operations alternativelyThe value can be one of the following strings −→ one, two three, four, five, six, seven, eight, nineThe operation can be one of the following strings −→ plus, minusFor example, if we implement the following in context of our class −Streak.one.plus.five.minus.three;Then the output should be −const output = 3;Output ExplanationBecause the operations that took place are −1 + 5 - 3 = 3ExampleFollowing is the code −const Streak = function() {    let value = 0;   ...

Read More

Implementing custom function like String.prototype.split() function in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

ProblemWe are required to write a JavaScript function that lives on the prototype object of the String class.It should take in a string separator as the only argument (although the original split function takes two arguments). And our function should return an array of parts of the string separated and split by the separator.ExampleFollowing is the code −const str = 'this is some string'; String.prototype.customSplit = (sep = '') => {    const res = [];    let temp = '';    for(let i = 0; i < str.length; i++){       const el = str[i];       ...

Read More
Showing 1341–1350 of 61,248 articles
« Prev 1 133 134 135 136 137 6125 Next »
Advertisements