22 lines
563 B
JavaScript
22 lines
563 B
JavaScript
|
var input = require("fs").readFileSync("input.txt").toString().replace("\n", "");
|
||
|
replace = str=>(str.split("").filter(a=>(a!="\n")).reduce((a,b)=>{
|
||
|
var c = a.pop();
|
||
|
if(c){
|
||
|
if(!((b!=c) && (b.toLowerCase()==c.toLowerCase()))){
|
||
|
a.push(c);
|
||
|
a.push(b);
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
a.push(b);
|
||
|
}
|
||
|
return a;
|
||
|
}, []).join(""));
|
||
|
|
||
|
var strs = [];
|
||
|
for(var i = 0; i < 26; i++){
|
||
|
strs.push(input.split("").filter((a)=>(a.toLowerCase().charCodeAt(0) != (97 + i))).join(""));
|
||
|
}
|
||
|
var lengths = strs.map(a=>(replace(a))).map(a=>(a.length));
|
||
|
console.log(Math.min.apply(null, lengths));
|