Tutorial by Examples: element

If an array happens to have one or more nil elements and these need to be removed, the Array#compact or Array#compact! methods can be used, as below. array = [ 1, nil, 'hello', nil, '5', 33] array.compact # => [ 1, 'hello', '5', 33] #notice that the method returns a new copy of the array w...
Each group ends with a line separator. If each item in your menu has its own group you will achieve the desired graphical output. It will work only if your different groups have different android:id. Also, in menu.xml remember to mention android:checkable="true" for single item and android...
reduce(_:combine:) can be used in order to combine the elements of a sequence into a single value. It takes an initial value for the result, as well as a closure to apply to each element – which will return the new accumulated value. For example, we can use it to sum an array of numbers: let numbe...
Generally, if we want to remove an element from an array, we need to know it's index so that we can remove it easily using remove(at:) function. But what if we don't know the index but we know the value of element to be removed! So here is the simple extension to an array which will allow us to re...
One of the nicest features of flexbox is to allow optimally fitting containers to their parent element. Live demo. HTML: <div class="flex-container"> <div class="flex-item">1</div> <div class="flex-item">2</div> <div class=&q...
2.12.2 You can use the minElement() and maxElement() methods to find the minimum or maximum element in a given sequence. For example, with an array of numbers: let numbers = [2, 6, 1, 25, 13, 7, 9] let minimumNumber = numbers.minElement() // Optional(1) let maximumNumber = numbers.maxElement()...
For immutable elements (e.g. None, string literals etc.): my_list = [None] * 10 my_list = ['test'] * 10 For mutable elements, the same construct will result in all elements of the list referring to the same object, for example, for a set: >>> my_list=[{1}] * 10 >>> print(my_...
When a single parameter is passed to the .attr() function it returns the value of passed attribute on the selected element. Syntax: $([selector]).attr([attribute name]); Example: HTML: <a href="/home">Home</a> jQuery: $('a').attr('href'); Fetching data attributes: jQue...
array = [1, 2, 3, 4] [first] = array # 1 [..., last] = array # 4 [first, middle..., last] = array # first is 1, middle is [2, 3], last is 4
Checkboxes <%= check_box_tag(:pet_dog) %> <%= label_tag(:pet_dog, "I own a dog") %> <%= check_box_tag(:pet_cat) %> <%= label_tag(:pet_cat, "I own a cat") %> This will generate the following html <input id="pet_dog" name="pet_dog&q...
In general, IBOutlets are used to connect an user interface object to another object, in this case a UIViewController. The connection serves to allow for the object to be affected my code or events programmatically. This can be done simply by using the assistant from a storyboard and control-clickin...
Inline display elements, usually such as span or a, will include up to one white-space character before and after them in the document. In order to avoid very long lines in the markup (that are hard to read) and unintentional white-space (which affects formatting), the white-space can be commented o...
.set-colors(@type) when (@type = error) { @base-color: #d9534f; background: @base-color; color: contrast(@base-color, lighten(@base-color, 25%), darken(@base-color, 25%)); border: 1px solid contrast(@base-color, lighten(@base-color, 25%), darken(@base-color, 25%)); } .set-colors(@type)...
Pair allows us to treat two objects as one object. Pairs can be easily constructed with the help of template function std::make_pair. Alternative way is to create pair and assign its elements (first and second) later. #include <iostream> #include <utility> int main() { std::p...
Elements can specify start, mid and end markers separately. Below are examples of start, mid and end markers for all elements that can be marked. Please note that Chrome does not currently (July 2016) calculate auto orientation correctly for start and end markers for polygons (bug# 633012), and also...
This trick helps you select an element using the ID as a value for an attribute selector to avoid the high specificity of the ID selector. HTML: <div id="element">...</div> CSS #element { ... } /* High specificity will override many selectors */ [id="element&quo...
Individual elements can be accessed through indexes. Python arrays are zero-indexed. Here is an example : my_array = array('i', [1,2,3,4,5]) print(my_array[1]) # 2 print(my_array[2]) # 3 print(my_array[0]) # 1
Here is an example : my_array = array('i', [1,2,3,4,5]) my_array.remove(4) # array('i', [1, 2, 3, 5]) We see that the element 4 was removed from the array.
pop removes the last element from the array. Here is an example : my_array = array('i', [1,2,3,4,5]) my_array.pop() # array('i', [1, 2, 3, 4]) So we see that the last element (5) was popped out of array.
index() returns first index of the matching value. Remember that arrays are zero-indexed. my_array = array('i', [1,2,3,4,5]) print(my_array.index(5)) # 5 my_array = array('i', [1,2,3,3,5]) print(my_array.index(3)) # 3 Note in that second example that only one index was returned, even though...

Page 9 of 15