作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想弄清楚如何检查字符串中是否包含三个升序字母和/或数字。例如,如果一个字符串有“manabcrt”然后有“abc”或“caSTLe567”,字符串中有“567”或“caSTLexyzand789”它有“xyz”和789 ...所以我想检查一下.我找到这个fiddle但它对重复的字母有效。
这是来自 fiddle 的代码:
var inputs = [
'helloworld',
'hellloworld',
'aaabc',
'abcddd',
'bbabba'];
var violators = [];
inputs.forEach(function(input) {
if (/(.)\1\1/.test(input)) {
violators.push(input);
}});
alert("VIOLATORS:\n" + violators.join('\n'));
最佳答案
您可以通过计算升序对来检查值。
var array = ['manabcrt', 'castle567', , 'castlexyzand789', 'helloworld', 'hellloworld', 'aaabc', 'abcddd', 'bbabba'],
check = array.filter(s => {
var v = 1;
return [...s].some((c, i, a) => {
v *= parseInt(c, 36) + 1 === parseInt(a[i + 1], 36);
return ++v === 3;
});
});
console.log(check);
对案例 '90'
和不包括 '9a'
的一些调整
var array = ['zab', '901', '9ab', 'manabcrt', 'castle567', , 'castlexyzand789', 'helloworld', 'hellloworld', 'aaabc', 'abcddd', 'bbabba'],
check = array.filter(s => {
var v = 1;
return [...s].some((c, i, a) => {
var l = parseInt(c, 36),
r = parseInt(a[i + 1], 36);
v *= l + 1 === r && l !== 9 && r !== 10 || l === 9 && r === 0 || l === 35 && r === 10;
return ++v === 3;
});
});
console.log(check);
关于Javascript检查字符串中的三个升序字母和数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48545590/
我是一名优秀的程序员,十分优秀!