如何跳出arf .find()
How To Break Out Of arr.find()?
这可能不是最佳实践,但我想知道是否有可能打破arr.find()方法。
这里有一些代码,我正在工作,我已经重新做了一个循环,但我想知道为什么这是不允许的?
任何帮助都是感激的!
我明白这不是解决手头问题的最佳方法,我只是好奇为什么休息不像预期的那样工作,我在哪里搞砸了我的想法?
//Using the JavaScript language, have the function SimpleSymbols(str) take the str parameterbeing passed and determine if it is an acceptable sequence by either return in the string true or false. The str parameter will be composed of + and = symbols with several letters between them (ie. ++d+===+c++==a) and for the string to be true each letter must be surrounded by a + symbol. So the string to the left would be false. The string will not be empty and will have at least one letter.
//loop through Array
//Determine if letter is surrounded by +
//If yes continue on and return true
//If no break loop and return false
function SimpleSymbols(str){
str = str.split('');
var pass = null;
function finder(char){
if (char.length === 1 && char.match(/[a-z]/i)){
var firstPlus = str.indexOf(char)- 1;
var secondPlus = str.indexOf(char)+ 1;
console.log(str[firstPlus]);
if (str[firstPlus] === '+' && str[secondPlus] === '+'){
pass = 'true';
} else {
pass = 'false'
break;
}
}
}
str.find(finder);
return pass
}
SimpleSymbols('++d+===+c++==a++q++');
以下代码将在5次迭代后打破循环:
SimpleSymbols('++-+d+===*c+3++==a++q-3++');
function SimpleSymbols(str){
str = str.split('');
var pass = null;
str.find(finder);
function finder(char, i){
console.log('Iteration No.' + i);
if (str.indexOf(char) && char.length === 1 && char.match(/[a-z]/i)){
var firstPlus = str.indexOf(char)- 1;
var secondPlus = str.indexOf(char)+ 1;
//console.log(str[firstPlus]);
if (str[firstPlus] === '+' && str[secondPlus] === '+'){
pass = 'true';
return pass;
} else {
pass = 'false';
}
}
}
console.log('FINAL RESULT = ' + pass);
return pass;
}
相关文章:
- .Find()仅显示可见元素
- jQuery(this).Pparent().Pparente().Prent().find()在iPad上不起作用
- 他们是如何使用angular/jqLite find()方法按属性名称和值选择元素的?ng conf 2015
- jQuery find() Issue
- 使用jquery Find()在复选框中查找图像
- strongloop script.js run find in before delete方法:如何同步运行异步方法
- 在另一个Find(..)的回调内部查找,如何逃离回调地狱
- $(e.target).find和template.find('input').value之间有什么区别
- 为什么我得到了一个“;未定义的“;使用“”从Find()返回值;这个“;论点
- .map-find元素一旦通过AJAX加载
- MongoDB collection.find()查询挂起
- 如何在jQuery中使用find
- 无法将参数传递给mongo find集合
- Ember.js-模型find()方法中的异步调用
- mongodb中db.collection.find()的返回类型是什么
- 使用 jquery .find() 遍历按类和存储属性选择元素
- .find 不起作用
- 如何在返回单个对象时递归使用 Array.prototype.find()
- JQuery .find() 函数用于多个数组
- 如何跳出arf .find()