PHP Name Resolution Rules

Malhar Lathkar
Updated on 18-Sep-2020 09:33:15

253 Views

IntroductionIn a PHP code, appearance of namespace is resolved subject to following rules −A namespace identifier without namespace separator symbol (/) means it is referring to current namespace. This is an unqualified name.If it contains separator symbol as in myspace\space1, it resolves to a subnamespace space1 under myspace. Such type of naming is relative namespace.Name of fully qualified namespace starts with \ character. For example, \myspace or \myspace\space1.Fully qualified names resolve to absolute namespace. For example \myspace\space1 resolves to myspace\space1 namespaceIf the name occurs in the global namespace, the namespace\ prefix is removed. For example namespace\space1 resolves to space1.However, if it occurs ... Read More

Finding Average Word Length of Sentences in JavaScript

AmitDiwan
Updated on 18-Sep-2020 09:31:28

455 Views

We are required to write a JavaScript function that takes in a string of strings joined by whitespaces. The function should calculate and return the average length of all the words present in the string rounded to two decimal placesExampleFollowing is the code −const str = 'This sentence will be used to calculate average word length'; const averageWordLength = str => {    if(!str.includes(' ')){       return str.length;    };    const { length: strLen } = str;    const { length: numWords } = str.split(' ');    const average = (strLen - numWords + 1) / numWords; ... Read More

Get Coordinates or Dimensions of Element with Selenium Python

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:30:30

3K+ Views

We can get coordinates or dimensions of elements with Selenium webdriver. Each of the elements have .size and .location properties which give the x, y coordinates and height, width of the element in the form of a dictionary.Syntax −loc = element.locations = element.sizeLet us consider an element for which we shall find coordinates and dimensions−Examplefrom selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #identify element l= driver.find_element_by_xpath("//img[@class='tp-logo']") #get x, y coordinates loc = l.location #get height, width s = l.size print(loc) print(s) driver.close()OutputRead More

Finding Lunar Sum of Numbers in JavaScript

AmitDiwan
Updated on 18-Sep-2020 09:30:04

302 Views

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

Defining Multiple Namespaces in Same File in PHP

Malhar Lathkar
Updated on 18-Sep-2020 09:29:16

703 Views

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

Equal Partition of an Array of Numbers in JavaScript

AmitDiwan
Updated on 18-Sep-2020 09:28:56

283 Views

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

Find Distinct Elements in JavaScript

AmitDiwan
Updated on 18-Sep-2020 09:27:48

147 Views

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]

PHP Aliasing and Importing Namespaces

Malhar Lathkar
Updated on 18-Sep-2020 09:27:25

928 Views

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

Filtering Out Primes from an Array in JavaScript

AmitDiwan
Updated on 18-Sep-2020 09:26:21

2K+ Views

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 ]

Select Item from Dropdown List Using Selenium WebDriver with Java

Debomita Bhattacharjee
Updated on 18-Sep-2020 09:26:08

2K+ Views

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

Advertisements