注意:我知道有很多类似的问题,我已经尝试对它们实施答案,但没有成功。
\n\n在我的 React Native 应用程序中,我有一个接受有限数量的自定义文本输入组件的表单。我正在尝试找到一种解决方案,当用户按下返回按钮时移动到下一个输入。\xe2\x80\xa8\xe2\x80\xa8I\xe2\x80\x99已经尝试了一些软件包,但似乎没有一个工作得很好与安卓。我\xe2\x80\x99ve也尝试过使用refs,但can\xe2\x80\x99t似乎很幸运(注意表单是一个功能组件)。当我尝试在浮动标签组件内访问它时,它不断返回未定义。
\n\n自定义组件:
\n\n<FloatLabelTextInput\n value={billingFirstName}\n onChangeText={newText => setBillingFirstName(newText)}\n autoCorrect={false}\n style={globalStyles.textInput}\n label="Billing First Name"\n />\xe2\x80\xa8\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\xa8浮动标签文本输入组件呈现文本输入(带有基于材质的浮动标签)。
\n\n\xe2\x80\xa8import React, { Component } from \'react\';\nimport {\n Alert,\n Button,\n View,\n TextInput,\n Animated,\n Image,\n TouchableOpacity,\n} from \'react-native\';\nimport colors from \'../utils/colors\';\n\nexport default class FloatLabelTextInput extends Component<Props> {\n static defaultProps = {\n editable: true,\n showHelp: false,\n };\n\n state = {\n isFocused: false,\n };\n\n\n\n componentDidUpdate() {\n Animated.timing(this.animatedIsFocused, {\n toValue: this.state.isFocused || this.props.value !== \'\' ? 1 : 0,\n duration: 200,\n …Run Code Online (Sandbox Code Playgroud) 除了数组[10,11,12]之外,我正在通过这个解决方案进行所有测试.我被卡住了.谢谢你的帮助
问题:
给定一个整数数组,找到它的任何两个相邻元素之间的最大绝对差值.
这个例子:
对于inputArray = [2,4,1,0],输出应为arrayMaximalAdjacentDifference(inputArray)= 3.
我的测试失败了:
输入:
inputArray:[10,11,13]
输出:0
预期产出:2
控制台输出:空
function arrayMaximalAdjacentDifference(arr) {
var dif = 0;
var max = 0;
for(var i = 0; i < arr.length; i++){
dif = arr[i] - arr[i+1];
if(dif > max){
max = dif;
}
}
return max;
}Run Code Online (Sandbox Code Playgroud)