Lunar SumThe concept of lunar sum says that the sum of two numbers is calculated, instead of adding the corresponding digits, but taking the bigger of the corresponding digits.For example −Let’s say, a = 879 and b = 768(for the scope of this problem, consider only the number with equal digits)Then the lunar sum of a and b will be −879We are required to write a JavaScript function that takes in two numbers and returns their lunar sum.ExampleFollowing is the code −const num1 = 6565; const num2 = 7385; const lunarSum = (num1, num2) => { const numStr1 = ... Read More
IntroductionMore than one namespaces can be defined in a single file with .php extension. There are two diferent methods prescribed for the purpose. combination syntax and bracketed syntaxMultiple Namespaces with Combination SyntaxIn this example two namespaces are defined one below the other. Resources in first namespace are available till second definition begins. If you want to make a namespace as current load it with use keyword.Example Live DemoOutputAbove code shows following outputmyspace1 : Hello World from space1 myspace2 : Hello World from space2 Hello World from space2 Hello World from space2Multiple Namespaces with bracketed SyntaxIn following example two namespaces are defined ... Read More
We are required to write a function that returns true if we can partition an array into one element and the rest, such that this one element is equal to the product of all other elements excluding itself, false otherwise.For example: If the array is −const arr = [1, 56, 2, 4, 7];Then the output should be trueBecause, 56 is equal to −2 * 4 * 7 * 1ExampleFollowing is the code −const arr = [1, 56, 2, 4, 7]; const isEqualPartition = arr => { const creds = arr.reduce((acc, val) => { let { prod, ... Read More
We are required to write a JavaScript function that takes in an array of literals, such that some array elements are repeated. We are required to return an array that contains that appear only once (not repeated).For example: If the array is:>const arr = [9, 5, 6, 8, 7, 7, 1, 1, 1, 1, 1, 9, 8];Then the output should be −const output = [5, 6];ExampleFollowing is the code −const arr = [9, 5, 6, 8, 7, 7, 1, 1, 1, 1, 1, 9, 8]; const findDistinct = arr => { const res = []; for(let i = 0; i < arr.length; i++){ if(arr.indexOf(arr[i]) !== arr.lastIndexOf(arr[i])){ continue; }; res.push(arr[i]); }; return res; }; console.log(findDistinct(arr));OutputFollowing is the output in the console −[5, 6]
IntroductionAn important feature of namespaces is the ability to refer to an external fully qualified name with an alias, or importing. PHP namespaces support following kinds of aliasing or importing −aliasing a class name, aliasing an interface name, aliasing a namespace namealiasing or importing function and constant names.In PHP, aliasing is accomplished with the use operator.use operatorExample Live Demo#test1.php OutputHello from mynamespace Hello from my new spacemultiple use statements combinedExample Live DemoOutputmyclass in mynamespace testclass in mynamespaceImporting and dynamic namessubstitute name of imported class dynamicallyExampleThe use keyword must be declared in the outermost or the global scope, or inside namespace declarations. Process ... Read More
We are required to write a JavaScript function that takes in the following array of numbers,const arr = [34, 56, 3, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34];and returns a new filtered array that does not contain any prime number.ExampleFollowing is the code −const arr = [34, 56, 3, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34]; const isPrime = n => { if (n===1){ return false; }else if(n === 2){ return true; }else{ for(let x = 2; x < n; x++){ if(n % x === 0){ return false; } } return true; }; }; const filterPrime = arr => { const filtered = arr.filter(el => !isPrime(el)); return filtered; }; console.log(filterPrime(arr));OutputFollowing is the output in the console −[ 34, 56, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34 ]
We can select an item from a dropdown list with Selenium webdriver. The Select class in Selenium is used to work with dropdown. In an html document, the dropdown is described with the tag.Let us consider the below html code for tag.For utilizing the methods of Select class we have to import org.openqa.selenium.support.ui.Select in our code. Let us see how to select an item with the Select methods−selectByVisibleText(arg) – An item is selected based on the text visible on the dropdown which matches with parameter arg passed as an argument to the method.Syntax−select = Select (driver.findElement(By.id ("txt")));select.selectByVisibleText ('Text');selectByValue(arg) ... Read More
We are required to write a JavaScript function that imitates a network request, for that we can use the JavaScript setTimeout() function, that executes a task after a given time interval.Our function should return a promise that resolves when the request takes place successfully, otherwise it rejectsExampleFollowing is the code −const num1 = 45, num2 = 48; const res = 93; const expectedSumToBe = (num1, num2, res) => { return new Promise((resolve, reject) => { setTimeout(() => { if(num1 + num2 === res){ resolve('success'); ... Read More
IntroductionWhen PHP parser encounters an unqulified identifier such as class or function name, it resolves to current namespace. Therefore, to access PHP's predefined classes, they must be referred to by their fully qualified name by prefixing \.Using built-in classIn following example, a new class uses predefined stdClass as base class. We refer it by prefixing \ to specify global classExampleIncluded files will default to the global namespace. Hence, to refer to a class from included file, it must be prefixed with \Example#test1.php This file is included in another PHP script and its class is referred with \when this file is included ... Read More
IntroductionIn absence of any namespace definition, all definitions of class, function etc. are placed in a global namespace. If a name is prefixed with \ , it will mean that the name is required from the global space even in the context of the namespace.Using global space specificationExampleIncluded files will default to the global namespace.Example#test1.php this will print empty stringwhen this file is included in another namespaceExample#test2.php OutputThis will print following outputtestspace