LogicApps Azure:
I have this array, and i need a function for get the value max for each property.
[
{
"limMec": 18,
"limMed": 6,
"maxCons": 1,
"maxImp": 188.23,
"maxVeh": 7
},
{
"limMec": 12,
"limMed": 6,
"maxCons": 10,
"maxImp": 200.66,
"maxVeh": 1
},
{
"limMec": 4,
"limMed": 9,
"maxCons": 1,
"maxImp": 1,
"maxVeh": 2
}
]
I need a function, not variables !!!
I have not found multiples functions for have a subarray with the differentes results.
Someone know?
With this i can get the value of an element, but not max of the collection:
max(body('Seleccionar')[1]['limMec'])
For this requirement, I provide a sample below for your reference:
1. I initialize a variable named data and store the same data with yours to simulate your situation.
2. Then add a "Select" action and click "Switch Map to key value mode", choose the variable data into "From" box and write expression item()?['limMec'] into "Map" box.
3. Now, initialize a variable result and use the expression max(body('Select')).
4. After running the logic app, we can get the max value of limMec.
Related
There two arrays, each of which will always contain an even, (though not equal) number of integers so that each pair will form a range, eg. 1..5, 8..12, etc.
var defaultArray: [Int] = [1, 5, 8, 12]
var priorityArray: [Int] = [1, 3, 5, 10, 13, 20]
What I'm looking for is a generic algorithm that will find each occurrence of where a range from priorityArray overlaps a range from defaultArray and will insert the priorityRange into the defaultArray while splitting the defaultRange apart if necessary.
The goal is to have a combined array of ranges while maintaining their original "types" like so:
var result: [Int] = [
1, 3, // priority
3, 5, // default
5, 10, // priority
10, 12, // default
13, 20 // priority
]
I'll use a simple struct to illustrate the final desired result:
var result: [Range] = [
Range(from: 1, until: 3, key: "priority"),
Range(from: 3, until: 5, key: "default"),
Range(from: 5, until: 10, key: "priority"),
Range(from: 10, until: 12, key: "default"),
Range(from: 13, until: 20, key: "priority")
]
We start with those arrays def and prio and first check if the intervals themselves are sorted wrt their start/end points. Those arrays would then contain the smallest number in the first array position. Ensure these arrays are simple/correct (=no overlapping intervals). If they are not, you can simplify/sanitise them.
We then initialise
array index d=0 to index the def array
array index p=0 to index the prio array
a new array result to hold all your newly created intervals.
a variable s=none to hold the current status
We now determine if the relation between the def[d] and prio[p].
If def[d]<prio[p], we set t=def[d], increment d and set s=def.
If def[d]> prio[p], we set t=prio[p], increment p and set s=prio.
If they are equal, we set t=prio[p], increment p and d and set s=both.
We can now initialise a new entry for the result array with start=def[0]. The priority is either def (if s==def) or prio (if s was prio or both). To determine the end, you can again compare def[d] with prio[p] to determine where it should end. At this point, you should adjust s again, but ensure that you keep track of the proper state which you're in (going from both to def, prio or none depending on the relation between def[d] and prio[p]). As mentioned in the comments of the OP, the different possibilities might require more clarification, but you should be able to incorporate them into a state.
Going from there, you can keep iterating and adjusting your variables until both are done (with d=len(def) and p=len(prio). You should end up with a nice array containing all the desired consolidated intervals.
This is basically a stateful sweep through the 2 arrays, keeping track of the current position in the integer range and advancing 1 (maybe 2) position(s) at a time.
let x = [1, 2, 2, 3, 3, 3, 1].reversed()
for element in x.method_name() {
print(element)
}
This returns
Value of type 'ReversedCollection<[Int]>' has no member 'method_name'.
Why? How do I reference the method I have created and have it do the functions I need it to do?
However, if I use the below, the problem seems to disappear. I would just like to pass in an array and do let the function do all, i.e.:
let x = Array([1, 2, 2, 3, 3, 3, 1].reversed())
Just in case you don't fully understand the motivation behind this overload of reversed returning a ReversedCollection instead of an Array, a ReversedCollection is just a "reversed view" of your original array. It is not a reversed copy of the original array. This is to save time and space, like a "lazy" collection. See this post for more details.
This is why you need the Array(...) initialiser to turn the reversed collection back into an array. You are opting out of the laziness.
On the other hand, there is another overload of reversed that returns an Array directly. Normally this overload is not selected because it is defined in a less specific type - Sequence, as opposed to Array. You need to give enough information about the type to use this overload:
let x: [Int] = [1, 2, 2, 3, 3, 3, 1].reversed()
I need to know, how to save integers from stdin into array, given by first integer in line... Ehm... hope you understand. I will give you an example.
On stdin I have:
0 : [ 1, 2, 3 ]
5 : [ 10, 11, 12, 13]
6 : [ 2, 4, 9 ]
0 : [ 4, 9, 8 ]
5 : [ 9, 6, 7 ]
5 : [ 1 ]
And I need save these integers to the arrays like this:
0={1, 2, 3, 4, 9, 8}
5={10, 11, 12, 13, 9, 6, 7, 1}
6={2, 4, 9}
I absolutely don't how to do it. There is a problem, that the number of arrays(in this case - 0, 5, 6 - so 3 arrays ) can be very high and I need to work effectively with memory...So I guess i will need something like malloc and free to solve this problem, or am I wrong? The names of arrays (0, 5, 6) can be changed. Number of integers in brackets has no maximum limit.
Thank you for any help.
I go with the assumption, this is homework, and I go with the assumption, this isn't your first homework to do, so I won't present you a solution but instead some tips that would help you to solve it yourself.
Given the input line
5 : [ 10, 11, 12, 13]
I will call "5" the "array name" and 10, 11, 12 and 13 the values to add.
You should implement some system to map array names to indices. A trivial approach would be like this:
.
size_t num_arrays;
size_t * array_names;
Here, in your example input, num_arrays will end up being 3 with array_names[3] = { 0, 5, 6}. If you find a new array name, realloc and add the new array name. Also you need the actual arrays for the values:
int * * array;
you need to realloc array for each new array name (like you realloc array_names). array[0] will represent array array_names[0] here array 0, array[1] will represent array array_names[1] here array 5 and array[2] will represent array array_names[2] here array 6.
To access an array, find it's index like so:
size_t index;
for (size_t index = 0; index < num_arrays && array_names[index] != search; ++index) ;
The second step is easy. Once you figured out, you need to use array[index] to add elemens, realloc that one (array[index] = realloc(array[index], new size)) and add elements there array[index][i+old_size] = new_value[i].
Obviously, you need to keep track of the number of elements in your separate arrays as well ;)
Hint: If searching for the array names take too long, you will have to replace that trivial mapping part by some more sophisticated data structure, like a hash map or a binary search tree. The rest of the concept may stay more or less the same.
Should you have problems to parse the input lines, I suggest, you open a new question specific on this parsing part.
In algorithmic terms, you need map (associative array) from ints to arrays. This is solved long ago in most higher level languages.
If you have to implement it manually, you have a few options:
simple "master" array where you store your 0, 5, 6, 1000000 and then map them to indices 0, 1, 2, 3 by doing search in for each time you have to access it (it's too time consuming when ;
hash table: write simple hash function to map 0, 5, 6, 1000000 (they're called keys) to values less than 1000, allocate array of 1000 elements and then make "master" array structures for each hash function result;
some kind of tree (e.g. red-black tree), may be a bit complex to implement manually.
Last two structures are part of programming classic and are well described in various articles and books.
def unique(arr)
return arr.keep_if { |x| arr.count(x) == 1 }
end
print unique([2, 5, 5, 4, 22, 8, 2, 8])
#=> [4, 22, 2]
The value 2 appears twice in the array, but using the following method incorrectly returns it. Why does that happen, and what can I do to fix it?
Unfortunately, this is due to some hidden behavior in how keep_if works. To illustrate this behavior, we can make use of the lowest-hanging fruit in our debugging orchard, good ol' puts:
def unique(arr)
return arr.keep_if { |x|
puts x, arr.join(',')
arr.count(x) == 1
}
end
print unique([2, 5, 5, 4, 22, 8, 2, 8])
This gives us the following as output:
2
2,5,5,4,22,8,2,8
5
2,5,5,4,22,8,2,8
5
2,5,5,4,22,8,2,8
4
2,5,5,4,22,8,2,8
22
4,5,5,4,22,8,2,8
8
4,22,5,4,22,8,2,8
2
4,22,5,4,22,8,2,8
8
4,22,2,4,22,8,2,8
[4, 22, 2]
Look carefully at exactly what happens whenever the method discovers a new value it wants to keep: it stores that value in one of the early indexes in the array, overwriting what's already there. The next time it finds a value it wants to keep, it places it in the next spot, and so on.
This means that the first time keep_if looks at 2, it sees two of them and so decides to skip it. But it then sees a 4 that it wants to keep, and overwrites the first 2. Thus, the second time it sees a 2, it decides to keep it.
You are changing an array while you iterate over it. This is considered undefined behavior by Matz himself and you should avoid doing it if you want to avoid strange behavior like the one you see there.
Instead of your keep_if method, you should use this instead:
arr.select{ |x| arr.count(x) == 1 }
This won't change the array in place but will return a new one however.
I'm relatively new to AngularJS, so maybe my question is stupid, but I cannot find an answer.
I have prepared example to explain my problem, it can be found here.
When controller instantiates it has some values passed from parent scope. In my example:
$scope.modelId = 2;
$scope.sizeA = 2; // this is initial values
$scope.sizeB = 180; // for select elements
Then controller requests from server other values for the lists. It loads:
"sizesA": [1, 2, 6, 9, 10],
"sizesB": [120, 180, 300]
After data is loaded, we can see initialized selects on page:
SizeA: <select ng-model="sizeA" ng-options="s for s in model.sizesA"></select>
SizeB: <select ng-model="sizeB" ng-options="s for s in model.sizesB"></select>
sizeB is initialized to value 180 (as expected), but sizeA is initialized to value 6 (with index 2) instead of value 2.
When I specify $scope.sizeA = 9; in controller (there is no index 9, but there such value) it selects item with value 9.
So the question: how can I tell angular to use value
Add track by:
<select ng-model="sizeA"
ng-options="size for size in model.sizesA track by size"></select>