We are provided two numbers N which defines a range [1, N] and D which is a difference.The goal is to find all the numbers in the range [1, N] such that the [ number - (sum of its digits) ] > D. We will do this by traversing numbers from 1 to N and for each number we will calculate its digit sum using a while loop. Check if the number and calculated digit sum has a difference more than D.Let’s understand with examples.Input N=15 D=5Output Numbers such that difference b/w no. and its digit sum greater than value D: 6Explanation Numbers ... Read More
We are provided two numbers START and END to define a range of numbers.The goal is to find all the numbers in the range [START, END] that are divisible by all of its non-zero digits . We will do this by traversing numbers from START to END and for each number we will check if the number is divisible by all non-zero digits using a while loop. If yes increment count.Let’s understand with examples.Input START=10 END=20Output Numbers that are divisible by all its non-zero digits: 14Explanation Numbers 10, 11, 12, 15, 20 are divisible by all their non-zero digits.Input START=100 END=200Output Numbers that are divisible ... Read More
We are provided a number N. The goal is to find the numbers that are divisible by X and not by Y and are in the range [1, N].Let’s understand with examples.Input N=20 X=5 Y=20Output Numbers from 1 to N divisible by X not Y: 2Explanation Only 5 and 15 are divisible by 5 and not 10.Input N=20 X=4 Y=7Output Numbers from 1 to N divisible by X not Y: 5Explanation Numbers 4, 8, 12, 16 and 20 are divisible by 4 and not 7.Approach used in the below program is as followsWe take an integer N.Function divisibleXY(int x, int y, int n) returns a count ... Read More
We are provided two numbers START and END to define a range of numbers. And also an array of positive numbers Arr[]. The goal is to find all the numbers that are divisible by all elements of Arr[] and are in the range [START, END] .Method 1 ( Naive Approach )We will do this by traversing numbers from START to END and for each number we will check if the number is divisible by all elements of the array. If yes increment count.Method 2 ( check divisibility by LCM of array elements )We will find the LCM of all array ... Read More
We are provided a number N. The goal is to find the numbers that have 0 as digit and are in the range [1, N].We will do this by traversing numbers from 10 to N ( no need to check from 1 to 9 ) and for each number we will check each digit using a while loop. If any digit is found as zero increment count and move to next number otherwise reduce the number by 10 to check digits until number is >0.Let’s understand with examples.Input N=11Output Numbers from 1 to N with 0 as digit: 1Explanation Starting from i=10 to ... Read More
We are provided two numbers START and END to define a range of numbers. The goal is to find the numbers that have only 2 and 3 as their prime factors and are in the range [START, END].We will do this by traversing numbers from START to END and for each number we will check if the number is divisible by 2 and 3 only. If divisible, divide it and reduce it. If not, break the loop. In the end if the number is reduced to 1 then it has only 2 and 3 as its factors.Let’s understand with examples.Input START=20 ... Read More
We are given an array Arr[] of integers with length n and a number M. The array is only containing positive integers. The goal is to count the triplets of elements of Arr[] which have product equal to M.We will do this by using three for loops. Increment count if arr[x]*arr[y]*arr[z]=M and x!=y!=z. (0
The colon (:) can be used when you want to define the property to an object while equal (=) can be used when you want to assign a value to a variable.ExampleFollowing is the code −var studentDetails = { "studentId": 101, "studentName": "John", "studentSubjectName": "Javascript", "studentCountryName": "US" } console.log(studentDetails); var firstName = "David"; console.log(firstName);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo325.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo325.js { studentId: 101, studentName: 'John', studentSubjectName: 'Javascript', studentCountryName: 'US' } David
To remove child elements, set the innerHTML to ‘’.ExampleFollowing is the code − Document Javascript MySQL Remove the items remove.onclick = () => { const element = document.getElementById("removeAllChildElements"); element.innerHTML = ''; } To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor.OutputThis will produce the following output −Now you can click the button “Remove the items”. It will remove all the elements inside the box.OutputThis will produce the following output −
Use the map() function correctly to save elements.ExampleFollowing is the code −const addIndexValueToArrayElement = function (arrObject) { const updatedArrayValue = []; arrObject.forEach(function (ob) { const mapValue = ob.map(function (value) { return value + arrObject.indexOf(ob) }) updatedArrayValue.push(mapValue) }) return updatedArrayValue; }; const output = addIndexValueToArrayElement([ [4, 5], [7, 56], [34, 78], ]); console.log(output);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo323.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo323.js [ [ 4, 5 ], [ 8, 57 ], [ 36, 80 ] ]