-
Code function removeEveryThird(str) { return str .split('') .filter((x, i) => i === 0 || i % 3) .join('') }
Test Cases const chai = require("chai"); const assert = chai.assert; describe("Solution", function() { it("This test passes", function() { assert.strictEqual(removeEveryThird('hello world'), 'helo ord'); }); it("This test fails (fix code - not test)", function() { assert.strictEqual(removeEveryThird('how you doing'), 'howyo din'); }); it("This test fails (fix code - not test)", function() { assert.strictEqual(removeEveryThird('abc'), 'abc'); }); it("This test fails (fix code - not test)", function() { assert.strictEqual(removeEveryThird('1234 56789 10112314'), '123 578 11131'); }); it("This test fails (fix code - not test)", function() { assert.strictEqual(removeEveryThird(' 00111222'), ' 001122'); }); });
Output:
-
Code - function removeEveryThird(str) {
const strArr = str.split('');const newArr = [];strArr.forEach((char, index) => {if (index === 0 || index % 3 !== 0) {newArr.push(char);}})console.log(newArr.join(''));return newArr.join('');- return str
- .split('')
- .filter((x, i) => i === 0 || i % 3)
- .join('')
- }
Test Cases - const chai = require("chai");
- const assert = chai.assert;
- describe("Solution", function() {
- it("This test passes", function() {
- assert.strictEqual(removeEveryThird('hello world'), 'helo ord');
- });
- it("This test fails (fix code - not test)", function() {
- assert.strictEqual(removeEveryThird('how you doing'), 'howyo din');
- });
- it("This test fails (fix code - not test)", function() {
- assert.strictEqual(removeEveryThird('abc'), 'abc');
- });
- it("This test fails (fix code - not test)", function() {
- assert.strictEqual(removeEveryThird('1234 56789 10112314'), '123 578 11131');
- });
- it("This test fails (fix code - not test)", function() {
- assert.strictEqual(removeEveryThird(' 00111222'), ' 001122');
- });
- });
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}