For loop coffeescript:break for with if语句

For loop coffeescript:break for with if语句,for-loop,coffeescript,break,For Loop,Coffeescript,Break,我试图找到通过数组实现循环的最佳方法,数组在匹配“if”语句后应返回一个值 我有两个字符串,正在尝试遍历它们的字符并比较它们(对于排序函数)。我需要在满足比较条件后中断迭代 最好是这样: a = 'here is one' b = 'here is two' if a.charCodeAt(i) < b.charCodeAt(i) then -1 else 1 for i in [0...a.length] when a.charCodeAt(i) != b.charCodeAt(i)

我试图找到通过数组实现循环的最佳方法,数组在匹配“if”语句后应返回一个值

我有两个字符串,正在尝试遍历它们的字符并比较它们(对于排序函数)。我需要在满足比较条件后中断迭代

最好是这样:

a = 'here is one'
b = 'here is two'
if a.charCodeAt(i) < b.charCodeAt(i) then -1 else 1 for i in [0...a.length] when a.charCodeAt(i) != b.charCodeAt(i)
a='这里有一个'
b='这里有两个'
如果a.charCodeAt(i)
但是,这意味着:

if (a.charCodeAt(i) < b.charCodeAt(i)) {
  return -1;
} else {
  _results = [];
  for (i = _i = 0, _ref = a.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
    if (a.charCodeAt(i) !== b.charCodeAt(i)) {
      _results.push(1);
    }
  }
  return _results;
}
_results = [];
for (i = _i = 0, _ref = a.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
  if (a.charCodeAt(i) !== b.charCodeAt(i)) {
    _results.push(pos = (a.charCodeAt(i) < b.charCodeAt(i) ? -1 : 1));
  }
}
return _results;
return ((function() {
  var _i, _ref, _results;
  _results = [];
  for (index = _i = 0, _ref = a['dep'].length; 0 <= _ref ? _i < _ref : _i > _ref; index = 0 <= _ref ? ++_i : --_i) {
    _results.push((function() {
      if (a['dep'].charCodeAt(index) < b['dep'].charCodeAt(index)) {
        return -1;
      } else {
        return 1;
      }
    })());
  }
  return _results;
})())[0];
if(a.charCodeAt(i)对于(i=_i=0,_ref=a.length;0 _ref;i=0,只需使用多行代码,就可以让它更可读

a = 'here is one'
b = 'here is two'
[x] = for i in [0...a.length] when a.charCodeAt(i) != b.charCodeAt(i)
    if a.charCodeAt(i) < b.charCodeAt(i) then -1 else 1 
a='这里有一个'
b='这里有两个'
[x] =当a.charCodeAt(i)!=b.charCodeAt(i)时,[0…a.length]中的i
如果a.charCodeAt(i)
Uhm…
'foo'.localeCompare'bar'
。。。!?
return ((function() {
  var _i, _ref, _results;
  _results = [];
  for (index = _i = 0, _ref = a['dep'].length; 0 <= _ref ? _i < _ref : _i > _ref; index = 0 <= _ref ? ++_i : --_i) {
    _results.push((function() {
      if (a['dep'].charCodeAt(index) < b['dep'].charCodeAt(index)) {
        return -1;
      } else {
        return 1;
      }
    })());
  }
  return _results;
})())[0];
a = 'here is one'
b = 'here is two'
[x] = for i in [0...a.length] when a.charCodeAt(i) != b.charCodeAt(i)
    if a.charCodeAt(i) < b.charCodeAt(i) then -1 else 1