Skip to content
Advertisement

ws.write = (result.join(‘,’) + ‘n’); && TypeError: result.join is not a function …how i solve this type error

help to solve in this javascript problem. Give me clear documentation about (join).

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

const a = readLine().replace(/s+$/g, '').split(' ').map(aTemp => parseInt(aTemp, 10));

const b = readLine().replace(/s+$/g, '').split(' ').map(bTemp => parseInt(bTemp, 10));

const result = compareTriplets(a, b);

ws.write = (result.join(',') + 'n');

ws.end();

}

Advertisement

Answer

Clear documentation for join

const result = compareTriplets(a, b);

Not sure what compareTriplets is but based on the word compare I am assuming it returns a boolean. You are trying to join a boolean expression. If you want one string containing of A and B then put A and B into an array and then use join. But with so little information it is hard to understand what you are trying to accomplish.

Based on your code I am assuming A and B both are arrays. If you want to join the elements together do this. Also assuming result is a boolean.

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

const a = readLine().replace(/s+$/g, '').split(' ').map(aTemp => parseInt(aTemp, 10));

const b = readLine().replace(/s+$/g, '').split(' ').map(bTemp => parseInt(bTemp, 10));

const result = compareTriplets(a, b);

if(result){
     ws.write = (a.join(',') + ',' + b.join(',') + 'n');
}
ws.end();
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement