I would like to give some feedback about ...
Your result: "hello"
Right result: ""
Fail: commonWords(["one,two,three","four,five,six"])
My result is "hello"?!
In my browser this code works correct. It returns empty string. Right?
"use strict"
var arrayEmpty = [];
function commonWords(string1, string2) {
var arrayString1 = string1.split(',');
var arrayString2 = string2.split(',');
for (var i = 0; i < arrayString1.length; i++) {
for (var n = 0; n < arrayString2.length; n++) {
if (arrayString1[i] === arrayString2[n]) {
arrayEmpty.push(arrayString1[i]);
}
}
}
for (var j = 0; j < arrayEmpty.length; j++) {
for (var k = 0; k < arrayEmpty.length; k++) {
if (arrayEmpty[k] > arrayEmpty[k+1]) {
var temp = arrayEmpty[k];
arrayEmpty[k] = arrayEmpty[k+1];
arrayEmpty[k+1] = temp;
}
}
}
if (arrayEmpty[0] == undefined) {
return arrayEmpty.join();
}
return arrayEmpty.join(',');
}
From: https://js.checkio.org/mission/common-words/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Created at: 2017/10/03 00:05; Updated at: 2017/10/03 11:32
The question is resolved.