Skipping every other element after the first [duplicate]
def altElement(a): return a[::2]
def altElement(a): return a[::2]
x(end+1) = newElem is a bit more robust. x = [x newElem] will only work if x is a row-vector, if it is a column vector x = [x; newElem] should be used. x(end+1) = newElem, however, works for both row- and column-vectors. In general though, growing vectors should be avoided. If you do this … Read more
If you just need to test basic equality, this can be done with the basic JDK without modifying the input lists in the one line !Collections.disjoint(list1, list2); If you need to test a specific property, that’s harder. I would recommend, by default, list1.stream() .map(Object1::getProperty) .anyMatch( list2.stream() .map(Object2::getProperty) .collect(toSet()) ::contains) …which collects the distinct values in … Read more
I can suggest 2 ways. First way define your variables before call the javascript, inside the .aspx file that can be compiled. var ButtonXXXID = <%=buttonXXX.ClientID%> // and now include your javascript and use the variable ButtonXXXID Second way in the external javascript file, write your code as: function oNameCls(ControlId1) { this.ControlId1 = ControlId1; this.DoYourWork1 … Read more
appendChild will remove the node from wherever it is before appending it to its new location, so you need to make copies of the node instead. You can use cloneNode for that. The true makes cloneNode perform a deep clone, i.e. with all its child nodes. for(var i = 0; i < urls.length; i++){ sliderBody.appendChild(slide.cloneNode(true)); … Read more
Use count() twice; one time in default mode and one time in recursive mode. If the values match, the array is not multidimensional, as a multidimensional array would have a higher recursive count. if (count($array) == count($array, COUNT_RECURSIVE)) { echo ‘array is not multidimensional’; } else { echo ‘array is multidimensional’; } This option second … Read more
document.getElementById() only supports one name at a time and only returns a single node not an array of nodes. You have several different options: You could implement your own function that takes multiple ids and returns multiple elements. You could use document.querySelectorAll() that allows you to specify multiple ids in a CSS selector string . … Read more
There is no consensus on best practice, and according to the author of the spec, Ian Hickson, it does not matter.
You can create a temporary parent node, and get the innerHTML content of it: var el = document.createElement(“p”); el.appendChild(document.createTextNode(“Test”)); var tmp = document.createElement(“div”); tmp.appendChild(el); console.log(tmp.innerHTML); // <p>Test</p> EDIT: Please see answer below about outerHTML. el.outerHTML should be all that is needed.