TEST MOCHA, got error "a.filter is not a function"

I try use MOCHA test. Need remove dublicate words in array. It my test. I got errors "TypeError: a.filter is not a function
at removeDuplicateWords (test.js:3:14)
at Context. (test.js:16:24)
at processImmediate (internal/timers.js:461:21)"
my test:

function removeDuplicateWords(a=[]){ 
	let arr2= a.filter((item, index)=>a.indexOf(item) == index )
return arr2	
}

////

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

describe("Basic tests", () => {
  it("Testing for fixed tests", () => {
    assert.strictEqual(removeDuplicateWords('alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'), 'alpha beta gamma delta');
  });
});

You are sending a string into the function, not an array. String doesn't have a .filter function.

Try

assert.strictEqual(removeDuplicateWords('alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'.split(' ')), 'alpha beta gamma delta');

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.