当前位置 : 主页 > 网络编程 > JavaScript >

颠三倒四,七上八下,十五的月亮十六圆

来源:互联网 收集:自由互联 发布时间:2021-06-30
获得这个游戏的结果 //颠三倒四,七上八下,十五的月亮十六圆var result = [];for (var i = 0; i = 100; i++) { var str = i.toString(); if (str.indexOf("3") = 0) { result.push(replaceChat(str, str.indexOf("3"), "4") + "(
获得这个游戏的结果
//颠三倒四,七上八下,十五的月亮十六圆

var result = [];

for (var i = 0; i <= 100; i++) {

  var str = i.toString();
  if (str.indexOf("3") >= 0) {
    result.push(replaceChat(str, str.indexOf("3"), "4") + "(" + i + ")");
    continue;
  }

  if (str.indexOf("4") >= 0) {
    result.push(replaceChat(str, str.indexOf("4"), "3") + "(" + i + ")");
    continue;
  }

  if (str.indexOf("7") >= 0) {
    result.push("上" + "(" + i + ")");
    continue;
  }

  if (str.indexOf("8") >= 0) {
    result.push("下" + "(" + i + ")");
    continue;
  }

  if (str.indexOf("5") >= 0) {
    result.push("月亮" + "(" + i + ")");
    continue;
  }

  if (str.indexOf("6") >= 0) {
    result.push("圆" + "(" + i + ")");
    continue;
  }

  result.push(i + "(" + i + ")");
}

str = ""
for (var i = 0; i < result.length; i++) {
  str += result[i];
  str += " ";
  if (i % 5 == 0) {
    console.log(str);
    str = ""
  }
}
console.log(str);

console.log(result);



function replaceChat(source, pos, newChar) {
  if (pos < 0 || pos >= source.length || source.length == 0) {
    return "invalid parameters...";
  }
  var iBeginPos = 0,
    iEndPos = source.length;
  var sFrontPart = source.substr(iBeginPos, pos);
  var sTailPart = source.substr(pos + 1, source.length);
  var sRet = sFrontPart + newChar + sTailPart;
  return sRet;
}
网友评论