Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I use Simone´s solution to store string arrays and present them in a List:
How to Store Nested Arrays in #AppStorage for SwiftUI
I tried to add a row delete function to the List:
.onDelete(perform: removeRows)
func removeRows(at offsets: IndexSet) {
getStrings(data: albums).remove(atOffsets: offsets)
}
I understand that this does not work because the function call returns an immutable value and I try to mutate it. How to resolve that?
Just add following delete function. You first get all string, then remove at offset and then store it back.
func removeRows(at offsets: IndexSet) {
var tmpAlbums = getStrings(data: albums)
tmpAlbums.remove(atOffsets: offsets)
albums = Storage.archiveStringArray(object: tmpAlbums)
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
I want to know the items that repeated a specified number of times in Spark (Scala).
With an RDD like this:
rdd = [text1,text2,text3,text4,text2,text4,text1,text1]
if the time = 2 the output should be [text2,text4].
Say you have an RDD that has been created like this:
val df: RDD[String] = spark.sparkContext.parallelize(Seq(
"text1", "text2", "text3", "text1", "text2", "text4"
))
You can use countByValue followed by a filter and keys, where 2 is your time value:
df.countByValue().filter(tuple => tuple._2 == 2).keys
If we do a println, we ge the following output:
[text1, text2]
Hope this is what you want, good luck!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
In python I can return how value what I append in the array
valuesinPy= []
for i range(len(value)) :
valuesinPy.append(value[i])
return valuesinPy
It's able to return all value I want to append in golang
valueappend =make(map[strig]string)
for i :=range value{
valueappend['abs']=value[i]
}
return valueappend
it's all same
But the value return same I got confused
Problem fix
I use the map [string]interface{}{} I less one struct of slice
valueappend:=map[string]interface{}{}
for i :=range value{
valueappend= append(valueappend, map[string]interface{}{
"valueIwant append" value[i] :
}
}
return valueappend
One issue I can see is that the key you are using is same in all iterations of the loop
valueappend['abs']=value[i]
This will overwrite all previous values and you will only have the last one in the loop be saved. In the end you will get a map with just one value. I'm guessing that's not what you want here. Use can use a unique key for each iteration as follows, or something else along the same line
for i := range value {
valueappend[i]=value[i]
}
#范紀予 please add more info and clarify what you are trying to achieve here.
You'll probably need to change the value of the map each time you go through the loop, or else every value from value[i] will keep writing to that same field in the map, leaving with the last value of i as your only value in the map
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So I am having problems when adding a quantity to an item. For example, the item Fist has a quantity of 1 and id 1. In the void addQuantity(int id, int quantity) function, i "did it" so when you type addQuantity(1, 1) for example, the item fist (which has rarity 1) will get quantity 2 but it just doesn't do anything. Can you guys help me fix it? I just need a working addQuantity, setQuantity and removeQuantity function.
Code: https://hastebin.com/itacijacur.cpp
The code that addQuantity executes is:
this->inventoryVec[id].quantity += quantity;
Here, you are using id as the index within inventoryVec. That's not the same as the id of the Item. In the scenario you have set up in your code, the index of the "fist" Item is actually 0, since it is the one and only Item added to the vector.
If you really want the addQuantity method to access items by their ID numbers, it would need to loop through the inventoryVec vector to search for an item whose ID number matches the id parameter of the method.
You are accessing the index of the vector as index 1, you are wanting to scan the vector and try and find the item that has the correct id, if found then you want to make the change to the item.
Change your addQuantity function to
void Inventory::addQuantity(int id, int quantity)
{
for (int i = 0; i < inventoryVec.size(); i++)
{
if (inventoryVec.at(i).getID() == id)
{
inventoryVec.at(i).quantity += quantity;
}
}
}
This will cycle through the vector and find the correct item, you were assuming the items index was equal to its ID.
Hope this helps, any questions just ask.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am working on a Power BI report. There are two dimensions DimWorkedClass and DimWorkedService. (The above snippet is obtained by exporting matrix values to csv.)
The requirement is to transform only the Worked Service Text5 into the Worked Class of Text5 as opposed to A (which is the current value).
It can be transformed at the backend, but is there any way to do it in Power BI?
This is trickier than it might appear, but it looks like this question has already been answered here:
Power Query Transform a Column based on Another Column
In your case, the M code would look something like this:
= Table.FromRecords(Table.TransformRows(#"[Source or Previous Step Here]",
(here) => Record.TransformFields(here, {"Worked Class",
each if here[Worked Service] = "text5" then "text5" else here[Worked Class]})))
(In the above, here represents the current row.)
Another answer points out a slightly cleaner way of doing this:
= Table.ReplaceValue(#"[Source or Previous Step Here]",
each [Worked Class],
each if [Worked Service] = "text5" then "text5" else [Worked Class],
Replacer.ReplaceText,{"Worked Class"})
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
The answer to the question below is given as 2. Why does refresh delete only the first row? Is it not expected that it deletes all rows of an internal table?
What will be output by the following code?
DATA: BEGIN OF itab OCCURS 0, fval type i, END OF itab.
itab-fval = 1. APPEND itab.
itab-fval = 2. APPEND itab.
REFRESH itab.
WRITE: /1 itab-fval.
A: 1
B: 2
C: blank
D: 0
Answer: B
If the code did not contain any syntax errors, e.g. the missing '-' when assigning the value 2 and when writing the value, then B is the correct answer but not for the reason you state. It is not that the REFRESH only removes the first line from the table, it is because REFRESH does not clear the header line of the table. So after the REFRESH the header line still has the latest assigned value which is 2. This can be easily ascertained when running the program in the debugger.
Note that the use of internal table with header lines is obsolete, as mentioned in SAP help.
You can use a clear command to clear the header line.
REFRESH itab.
CLEAR itab.