Creating Array using JSTL or EL

If you’re already on EL 3.0 (Tomcat 8+, WildFly 8+, GlassFish 4+, Payara 4+, TomEE 7+, etc), which supports new operations on collection objects, you can use ${[…]} syntax to construct a list, and ${{…}} syntax to construct a set. <c:set var=”alphabet” value=”${[‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’]}” scope=”application” /> If you’re not on EL 3.0 yet, use the ${fn:split()} … Read more

Get random elements from array in Swift

Xcode 11 • Swift 5.1 extension Collection { func choose(_ n: Int) -> ArraySlice<Element> { shuffled().prefix(n) } } Playground testing var alphabet = [“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”] let shuffledAlphabet = alphabet.shuffled() // “O”, “X”, “L”, “D”, “N”, “K”, “R”, “E”, “S”, “Z”, “I”, “T”, “H”, “C”, “U”, “B”, “W”, “M”, “Q”, “Y”, “V”, “A”, “G”, “P”, “F”, “J”] … Read more

How do I insert an element at the correct position into a sorted array in Swift?

Here is a possible implementation in Swift using binary search (from http://rosettacode.org/wiki/Binary_search#Swift with slight modifications): extension Array { func insertionIndexOf(_ elem: Element, isOrderedBefore: (Element, Element) -> Bool) -> Int { var lo = 0 var hi = self.count – 1 while lo <= hi { let mid = (lo + hi)/2 if isOrderedBefore(self[mid], elem) { … Read more

Does Matlab accept non-integer indices?

Additional observations: x(1.2:3) should theoretically be interpreted as: subsref(x, substruct(‘()’,1.2:3)). However, as mentioned in the question, “No rounding takes place when the indexing array is a standard array“, which causes the explicit subscripted reference to fail. This suggests that a mechanism similar to logical short-circuiting or perhaps multithreaded partitioning (where intermediate variable are “not really … Read more

How do you sort an array of structs in swift

Sort within the same array variable Sort functions bellow are exactly the same, the only difference how short and expressive they are: Full declaration: myArr.sort { (lhs: EntryStruct, rhs: EntryStruct) -> Bool in // you can have additional code here return lhs.deadline < rhs.deadline } Shortened closure declaration: myArr.sort { (lhs:EntryStruct, rhs:EntryStruct) in return lhs.deadline … Read more

tech