문제 링크 : Second Largest Digit in a String
/**
* @param {string} s
* @return {number}
*/
var secondHighest = function(s) {
let setArr = [...new Set([ ... s.replace(/[A-Z, a-z]/g,'').split('') ])].sort((a,b) => b-a)
if(setArr.length < 2) {
return -1
} else {
return setArr[1]
}
};
/**
* @param {string} s
* @return {number}
*/
var secondHighest = function(s) {
let setTemp = Array.from(new Set(s.replace(/\D/g,'').split(''))).sort();
if(setTemp[setTemp.length-2]){
return setTemp[setTemp.length-2];
}else{
return -1;
}
};