35. 문자열 정렬하기
function solution(strings, n) {
let sortString=[]
for(i=0; i<strings.length; i++){
addCha = strings[i][n]
strings[i] = addCha+strings[i]
}
strings.sort()
for(i=0; i<strings.length; i++){
strings[i] = strings[i].replace(strings[i][0],"")
sortString.push(strings[i])
}
return sortString
}
36. 내림차순으로 배치하기
function solution(s) {
let upperS = s.toUpperCase()
let upperSort=[]
let lowerSort=[]
let answer=""
for(i=0; i<s.length; i++){
if(s[i] == upperS[i]){
upperSort.push(s[i])
}else lowerSort.push(s[i])
}
answer = lowerSort.sort().reverse().join('')+upperSort.sort().reverse().join('')
return answer
}
37. 소수 만들기
function solution(nums) {
let pNumberCount = 0;
for(i = 0; i < nums.length; i++) {
for(j = i+1; j < nums.length; j++) {
for(k = j+1; k < nums.length; k++) {
let sum = nums[i] + nums[j] + nums[k];
if(isPrime(sum)) pNumberCount++;
}
}
}
return pNumberCount;
}
function isPrime(sum) {
for(let i = 2; i < sum; i++)
if(sum % i === 0) return false
return true
}
38.숫자 문자열과 영단어
function solution(s) {
let answer = ""
let numArry = ['zero','one','two','three','four','five','six','seven','eight','nine']
let matchNum=""
for(i=0; i<s.length; i++){
if(isNaN(s[i]) == false){
answer += s[i]
}else{
matchNum += s[i]
for(j=0; j<numArry.length; j++){
if(matchNum == numArry[j]){
answer += j
matchNum = ""
}
}
}
}
return Number(answer)
}