I need when cell for 'input' which are a list of numbers separated by comma ',' or blank space ' ' filled up, the next two cells will auto update with these numbers in ascending and descending orders subsequently.
I currently have error input.replace is not a function. Any idea to fix the syntax? Thanks
const [input, setInput] = useState('0')
const [sortAscen, setSortAcen] = useState(input.replace(/, +/g, ",").split(",").map(Number).sort((a, b) => a - b).toString())
const [sortDescen, setSortDescen] = useState(input.toString().replace(/, +/g, ",").split(",").map(Number).sort((a, b) => b - a).toString())
Don't use a state that depends on another state. Instead, move your formatting logic to functions whose output can be used directly in your markup.
Related
I'm trying to save just a number from a string I get from a paragraph but when I try to asign an alias to it and then check the value it returns undefined. I've tried a few solutions I found but none of those seem to work for me. These are two ways I tried (I tried another one similar to the second one but using split, had same result). The console.log inside of the 'then' doesn't show in the console, and when I try the alias after the code is when I get undefined.
cy.get('p')
.eq(1)
.should('have.text', '/[0-9]+/g')
.as('solNumber')
cy.get('p')
.eq(1)
.invoke('text')
.then((text)=>{
var fullText = text;
var pattern = /[0-9]+/g;
var number = fullText.match(pattern);
console.log(number);
})
.as('solNumber')
Please convert with + operator and return the numeric value if you want numeric type to be stored.
cy.get('p').eq(1)
.invoke('text')
.then(fullText => {
const number = fullText.match(/[0-9]+/);
return +number // text to numeric
})
.as('solNumber')
cy.get('#solNumber')
.should('eq', 42) // numeric type
});
Running your 2nd code on this,
<p>21</p>
<p>42</p>
gives the correct outcome
cy.get('p')
.eq(1)
.invoke('text')
.then((text)=>{
var fullText = text;
var pattern = /[0-9]+/g;
var number = fullText.match(pattern);
console.log(number); // logs 42
})
.as('solNumber')
cy.get('#solNumber')
.should('eq', '42') // passes
So, you need to inspect the DOM, it looks like it's not what you expect.
The first attempt you were passing a jquery element to the .should() and although some chainers change the subject yours did not so it saved the jquery element as solNumber.
The second attempt invokes the .text() which was passed to the .then() it logs the number correctly. However, you did not return anything at the end of the .then() block, therefore, solNumber should hold the entire paragraph.
This should help you out to extract the specific number and save it as an alias.
cy.get('p')
.invoke('text')
.invoke('trim')
.then(paragraph => {
const matcher = /some/
expect(paragraph).to.match(matcher) // check number is there
const indexOfText = paragraph.match(matcher) // get index of match text
return paragraph.substring(indexOfText.index, indexOfText.index + indexOfText[0].length) // return substring
})
.as('savedText')
cy.get('#savedText')
.then(cy.log) // will print out the number you seek
I'm trying to set multiple states in a for loop to be false or true depending on whether they meet the (if statement) requirement. The for loop will loop through an array of strings, each string represents a state. But I can't seem to use eval within this.setState function...
I have tried researching online but none of the solutions match my problem or what I'm trying to solve. I even tried eval(this.state.anything) = false but it still doesn't work and shows a left hand assign invalid error.
let businessState = [
"this.state.groupName",
"this.state.groupOwnerName",
"this.state.groupDesc",
"this.props.profile._id",
"this.state.businessName",
"this.state.businessDesc",
"this.state.businessRegNo",
"this.state.businessType",
"this.state.businessEmail",
"this.state.businessTel",
"this.state.businessWeChat",
"this.state.businessRegPhotoUri",
"this.state.businessSignPhotoUri"
];
var temp = ""
for (i = 0; i < businessState.length; i++) {
if (eval(businessState[i]) == ""){
temp = businessState[i]+ "Error"
this.setState({
eval(temp): true
})
}
}
As you can see from the code above, I want to evaluate the state, and if the value that this particular state holds is an empty string "", I want to set this state name + "Error" (For example, if this.state.email is empty string "" I want to set this.state.emailError to true.
Instead of this.setState({eval(temp): true}) try this.setState({[temp]: true}). The brackets will output the string value stored in temp as a variable name in setState.
This article gives a good explanation
This Stack Overflow question and the accepted answer also should help
I've got a system that generates and automatically maintains lots of spreadsheets on a Drive account.
Whenever I add data to the sheet I run a 'format' method to pass over and make sure everything is ok.
This generally does things like:
set the default font and size across the sheet
set up the heading row
freeze rows
In addition, I have the code below to make sure the first two columns (index 0 and 1) in the sheet are autoresizing to fit their contents. when I run it though, this element doesn't seem to make a difference. The font, column freezes etc all work.
Other notes:
I only want those 2 columns to auto-resize
the amount of rows in a sheet can vary
this job is appended to the end of several in requestList
My code:
requestList.Requests.Add(new Google.Apis.Sheets.v4.Data.Request()
{
AutoResizeDimensions = new AutoResizeDimensionsRequest()
{
Dimensions = new DimensionRange()
{
SheetId = Convert.ToInt32(sheetId),
Dimension = "COLUMNS",
StartIndex = 0,
EndIndex = 1
}
}
});
var updateRequest = sheetService.Spreadsheets.BatchUpdate(requestList, spreadSheetId);
var updateResponse = updateRequest.Execute();
Could the order which I request the 'format' changes be affecting things maybe? Can anyone help?
As written in the documentation,
the start index is inclusive and the end index is exclusive.
So, For the first two columns, it should be
startIndex = 0,
endIndex = 2
I am new to apache velocity, I want to create a subList Object from the List Objects which are coming from some service call in .vm file.
We need to render the list based on some logic in parts, for that we want to create sublist from list.
$table.getBooks() //contains all the Books objects
Below is the sample code which I tried but it did not work.
#set($segregatedList = [])
#set($size = $table.getLineItems().size())
#foreach($index in [0..$size-1])
#set($value = $index + 4)
#set($minimum = $math.min($nItems,$value))
$segregatedList.add($table.getBooks().subList($index,$minimum)))
$index += 4
#end
I executed the code, while rendering $segregatedList is coming as null.
I verified $table.getBooks() contains the Objects as when I am passing this,Objects are getting rendered successfully.
Can someone please tell what I am doing wrong or how can I create a sublist ?
First you are increment index with 4 and can cause an IndexOutOfBoundsException, so need to change until size-5 (and therefore remove math minimum check)
Second you are adding single Element instead of all Elements using addAll
Third your size check if on wrong parameter - should be on relevant $table.getBooks()
And last make sure your list have more than 5 elements
#set($segregatedList = [])
#set($size = $table.getBooks().size())
#foreach($index in [0..$size-5])
#set($value = $index + 4)
$segregatedList.addAll($table.getBooks().subList($index, $value)))
$index += 4
#end
I need to call the same screen (question) repeatedly in a Movelet for filling and send its fields to SAP.
The number of calls to the screen will be set dinamically depending on a variable value.
Is it possible to do that? How can I do it?
Thanks in advance.
it is possible. Create a method for generating a screen called (for instance) ADD_LOOP_SCR:
IV_SCREEN_KEY TYPE /MOVI/LZR_ANSWER_KEY Movilizer: Answer Key
IV_NEXT_SCR_KEY TYPE /MOVI/LZR_ANSWER_KEY Movilizer: Answer Key
CS_MOVELET TYPE /MOVI/MS_ST_BUSSTEP_STRUCTURE Movelet structure
implementation (Epsilon example)
DATA:
lr_screen TYPE REF TO /movi/ms_st_screen_epsilon,
lr_answer TYPE REF TO /movi/ms_st_answer.
APPEND INITIAL LINE TO cs_movelet-epsilon_screens REFERENCE INTO lr_screen.
lr_screen->key = iv_screen_key.
APPEND INITIAL LINE TO lr_screen->answers REFERENCE INTO lr_answer.
CONCATENATE 'AK_' iv_screen_key INTO lr_answer->key.
CONCATENATE 'CK_' iv_screen_key INTO lr_answer->client_key.
lr_answer->next_screen_key = iv_next_scr_key.
lr_answer->followup_action = /movi/dsd_if_const=>movilizer-followup_action_none.
add_XXXXXX_mel(
EXPORTING
...... if needed
CHANGING
ct_mel_expressions = lr_screen->mel_expressions
ct_validations = lr_screen->validations
ct_restrictions = lr_screen->restrictions ).
and then mainly in the GENERATE method:
es_movelet-first_screen_key = 'SK_LOOPSCREEN_001'.
DATA:
lv_i TYPE numc3,
lv_sk TYPE /movi/lzr_answer_key,
lv_next_sk TYPE /movi/lzr_answer_key.
DO 5 TIMES.
lv_i = sy-index.
CONCATENATE 'SK_LOOPSCREEN_' lv_i INTO lv_sk.
ADD 1 TO lv_i.
IF lv_i > 5.
lv_next_sk = /movi/lzr_if_constants=>movilizer_movelet_exit_key.
ELSE.
CONCATENATE 'SK_LOOPSCREEN_' lv_i INTO lv_next_sk.
ENDIF.
add_generate_printout_data_scr( EXPORTING iv_screen_key = lv_sk
iv_next_scr_key = lv_next_sk
CHANGING cs_movelet = es_movelet ).
ENDDO.
Good luck, cheers,
Aleq