xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Right in the Center (js string algorithm)

Right in the Center (js string algorithm)

codewars

https://www.codewars.com/kata/5f5da7a415fbdc0001ae3c69/train/javascript


function isInMiddle(seq) {
  // your goes below 
  let str = seq.replace(/abc/g, `$`);
  let left = str.slice(0, str.indexOf(`$`));
  let right = str.slice(str.indexOf(`$`) + 1);
  if(Math.abs(left.length - right.length) < 2) {
    return true;
  } else {
    return false;
  }
}


const chai = require("chai");
const assert = chai.assert;

describe("isInMiddle", function() {
  it("should test the examples", function() {
    assert.equal(isInMiddle("AAabcBB"), true);
    assert.equal(isInMiddle("AabcBB"), true);
    assert.equal(isInMiddle("AabcBBB"), false);

  });
});

https://codingbat.com/java

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-10-09 13:40  xgqfrms  阅读(197)  评论(3编辑  收藏  举报