Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Common Words by lleeeaaaannnnn
"use strict";
function commonWords(first, second) {
const set1 = new Set(first.split(','));
const set2 = new Set(second.split(','));
return ([...set1].filter((word) => set2.has(word)).sort().join(','));
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(commonWords("hello,world", "hello,earth"), "hello", "Hello");
assert.equal(commonWords("one,two,three", "four,five,six"), "", "Too different");
assert.equal(commonWords("one,two,three", "four,five,one,two,six,three"), "one,three,two", "1 2 3");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
July 11, 2018
Comments: