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 nlupton
"use strict";
function commonWords(first, second) {
const arr1 = first.split(',').sort();
const set2 = new Set( second.split(','));
return arr1.filter( x => set2.has(x) ).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!");
}
Nov. 27, 2017
Comments: