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);
});
});
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13785375.html
未经授权禁止转载,违者必究!