我的 React 应用程序中有一个复选框列表。当我按住 Shift 键并单击一个时 - 当前和最近选中的一个之间的其他应该被选中。
现在我正在尝试做这样的事情:
<input onChange={(e)=>this.handleCheckbox(e)} value={id} checked={this.state.selected.IndexOf(id) > -1} type="checkbox" />
handleCheckbox(e){
if(e.shiftKey){
console.log("shiftKey is hold")
}
//here goes some logic to save checkboxes in the state
}
Run Code Online (Sandbox Code Playgroud)
但条件if(e.shiftKey)永远不会被执行。我究竟做错了什么?
可能重复:
右移操作员的奇怪行为
你好
为什么这个函数的两个数字都打印相同?它不是循环移位.
unsigned int i=0x89878685;
int main()
{
printf("0x%x\n", i);
printf("0x%x\n", i>>32);
}
$ ./a.out
0x89878685
0x89878685
Run Code Online (Sandbox Code Playgroud)
所有编译器都以这种方式工作吗?
在C中你做这样的事情:
char var = 1;
while(1)
{
var = var << 1;
}
Run Code Online (Sandbox Code Playgroud)
在第8次迭代中,"<<"运算符将移出1并且var将为0.我需要执行移位以保持位移位.换句话说,我需要这个:
首字母----- 00000001
第一班 - 00000010
第二班 - 00000100
第3班 - 00001000
第四班 - 00010000
第五班 - 00100000
第6班 - 01000000
第7班 - 10000000
第8班 - 00000001(第8班,自动重启)
有没有相当于"<<"的东西,但实现这一点?
我想编写一个程序,根据用户的输入(正 - >,负< - )将数组向右或向左移动一定数量的位置.该程序必须具有O(n)复杂性.我是用这种方式写的,但它不能正常工作.在示例中,输出应为"2,3,4,5,6,1",但在我的版本中为"6,2,3,4,5,1".
#include <stdio.h>
#include <string.h>
#include <math.h>
void rotate(int *array, int N, int D);
int main(){
int i;
int array[] = {1, 2, 3, 4, 5, 6};
rotate(array, sizeof(array)/sizeof(int), 5);
for(i=0; i<sizeof(array)/sizeof(int); i++)
printf("%d\t", array[i]);
return 0;
}
void rotate(int *array, int N, int D){
int i, j, *tmp, d;
tmp = malloc(abs(D) * sizeof(int));
if(D<0){
d = abs(D);
for(i=d; i<N; i++){
tmp[i%d] = array[i];
array[i] = array[i-d];
array[i-d] = tmp[i%d];
}
}
if(D>0){
for(i=(N-D-1); i>=0; …Run Code Online (Sandbox Code Playgroud) 如何从bash中的参数列表中删除第n个元素?
Shift只显示删除前n个,但我想保留第一个.我想要的东西:
#!/bin/sh
set -x
echo $@
shift (from position 2)
echo $@
Run Code Online (Sandbox Code Playgroud)
所以当我调用它时 - 它会从列表中删除"house":
my.sh 1 house 3
1 house 3
1 3
Run Code Online (Sandbox Code Playgroud) 我知道shift key代码是16,enter key代码是13.
//@ catching any 'enter' keypress in textarea.
function textareaOnEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13)
{
//.. works only for 'enter'
}
});
}
Run Code Online (Sandbox Code Playgroud)
我认为它可以像这样简单:
function textareaOnShiftAndEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13 && e.which == 16)
{
//.. don't work for nothing
}
});
}
Run Code Online (Sandbox Code Playgroud)
但当然它根本无法正常工作.如何检查shift + enter按键?
我想检查数据的重叠,这里是数据
ID <- c(rep(1,3), rep(3, 5), rep(4,4),rep(5,5))
Begin <- c(0,2.5,3,7,8,7,25,25,10,15,17,20,1,NA,10,11,13)
End <- c(1.5,3.5,6,12,8,11,29,35, 12,19,NA,28,5,20,30,20,25)
df <- data.frame(ID, Begin, End)
df
ID Begin End
1 1 0.0 1.5
2 1 2.5 3.5
3 1 3.0 6.0*
4 3 7.0 12.0
5 3 8.0 8.0*
6 3 7.0 11.0*
7 3 25.0 29.0
8 3 25.0 35.0*
9 4 10.0 12.0
10 4 15.0 19.0
11 4 17.0 NA*
12 4 20.0 28.0
13 5 1.0 5.0
14 5 NA 20.0
15 …Run Code Online (Sandbox Code Playgroud) 我需要使用创建动态预测
v(t) = b0 + b1*v(t-1) + b2*v(t-2) + b3*x(t-1) + b4*x(t-2)
Run Code Online (Sandbox Code Playgroud)
数据集在时间0处看起来像这样.在实际数据中,有80个不同的x和100K"日期".
date v vLag1 vLag2 x xLag1 xLag2 b1 b2 b3 b4
2016-06-30 NA 105 95 33 11 23 0.2 3.2 -1.2 0.4
2016-07-01 NA NA NA 43 33 11 0.2 3.2 -1.2 0.4
2016-07-02 NA NA NA 52 43 33 0.2 3.2 -1.2 0.4
Run Code Online (Sandbox Code Playgroud)
目标是预测v,用值替换所有NA.我创建了vLag1,vLag2,xLag1,xLag2,这样我就可以 在一行中计算v.
所有的x和b都是提前知道的,所以我创建了上面显示的滞后x.该b的是系数.
对于每个日期,V(t)的被预测,并且该预测V(t)的的将反馈到下一个日期的v …
这就是我所拥有的:
class encoded
{
public static void main(String[] args)
{
String s1 = "hello";
char[] ch = s1.toCharArray();
for(int i=0;i<ch.length;i++)
{
char c = (char) (((i - 'a' + 1) % 26) + 'a');
System.out.print(c);
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经将字符串转换为数组,并且已经找到了如何进行移位的方法,但是现在我陷入了困境。
我想要的是从代码开始ch[0],读取字符,将其向右移(hto i),然后对数组中的每个字符执行相同操作,直到到达末尾。
现在,我的代码输出opqrs。我要它输出ifmmp。如果我更换了int i = 0在for带环int i = ch[0],它在启动i,但随后它只是输入ijklmno...
我希望它读取h,输出为i,读取e,输出为等f,直到到达数组的末尾。