학습 기록 (Learning Logs)/알고리즘
[programmers] 숫자 문자열과 영단어
devWonny
2022. 8. 23. 17:49
https://programmers.co.kr/skill_checks/411665?challenge_id=7777
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
https://school.programmers.co.kr/learn/courses/30/lessons/81301
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
return 에서 변수를 두개를 전달하지 못한다
function solution(s) {
var answer = "";
let temp = "";
for(word of s){
// console.log(isNaN(word))
console.log(word);
// console.log(isNaN(word*1));
if(isNaN(word*1)){//문자인 경우
temp += word;
// console.log("tt");
temp,answer= isPerpectWord(temp,answer);
console.log("temp>>>>>",temp);
}else{//숫자인경우
if(isEmptyArr(temp)){
answer+=word;
}
}
}
console.log("answer>>> ",answer);
return answer*1;
}
function isPerpectWord(temp,answer){
let wordGraph = [["zero",0],["one",1],["two",2],["three",3],["four",4],["five",5],["six",6],["seven",7],["eight",8],["nine",9]];
console.log("wordGraph.length>> ",wordGraph.length)
for(let i=0; i<wordGraph.length; i++){
console.log("isPerpectWord>>> ",temp);
console.log("isPerpectWord>>> wordGraph[i][0]>>",wordGraph[i][0]);
if(temp == wordGraph[i][0]){
answer += wordGraph[i][1];
temp = "";
return temp,answer;
}
}//end for
return temp,answer;
}
function isEmptyArr(arr) {
if(Array.isArray(arr) && arr.length === 0) {
return true;
}
return false;
}
입력값 〉 "one4seveneight"
기댓값 〉 1478
실행 결과 〉 실행한 결괏값 1이 기댓값 1478과 다릅니다.
출력 〉 o
wordGraph.length>> 10
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> o
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> o
n
wordGraph.length>> 10
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> on
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> on
e
wordGraph.length>> 10
isPerpectWord>>> one
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> one
isPerpectWord>>> wordGraph[i][0]>> one
temp>>>>> one
4
s
wordGraph.length>> 10
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> ones
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> ones
e
wordGraph.length>> 10
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> onese
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> onese
v
wordGraph.length>> 10
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> onesev
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> onesev
e
wordGraph.length>> 10
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> oneseve
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> oneseve
n
wordGraph.length>> 10
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> oneseven
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> oneseven
e
wordGraph.length>> 10
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> onesevene
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> onesevene
i
wordGraph.length>> 10
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> onesevenei
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> onesevenei
g
wordGraph.length>> 10
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> oneseveneig
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> oneseveneig
h
wordGraph.length>> 10
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> oneseveneigh
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> oneseveneigh
t
wordGraph.length>> 10
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> oneseveneight
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> oneseveneight
answer>>> 1
테스트 2
입력값 〉 "23four5six7"
기댓값 〉 234567
실행 결과 〉 실행한 결괏값 4이 기댓값 234567과 다릅니다.
출력 〉 2
3
f
wordGraph.length>> 10
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> f
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> f
o
wordGraph.length>> 10
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> fo
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> fo
u
wordGraph.length>> 10
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> fou
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> fou
r
wordGraph.length>> 10
isPerpectWord>>> four
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> four
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> four
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> four
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> four
isPerpectWord>>> wordGraph[i][0]>> four
temp>>>>> four
5
s
wordGraph.length>> 10
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> fours
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> fours
i
wordGraph.length>> 10
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> foursi
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> foursi
x
wordGraph.length>> 10
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> foursix
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> foursix
7
answer>>> 4
테스트 3
입력값 〉 "2three45sixseven"
기댓값 〉 234567
실행 결과 〉 실행한 결괏값 3이 기댓값 234567과 다릅니다.
출력 〉 2
t
wordGraph.length>> 10
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> t
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> t
h
wordGraph.length>> 10
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> th
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> th
r
wordGraph.length>> 10
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> thr
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> thr
e
wordGraph.length>> 10
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> thre
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> thre
e
wordGraph.length>> 10
isPerpectWord>>> three
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> three
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> three
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> three
isPerpectWord>>> wordGraph[i][0]>> three
temp>>>>> three
4
5
s
wordGraph.length>> 10
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threes
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threes
i
wordGraph.length>> 10
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threesi
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threesi
x
wordGraph.length>> 10
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threesix
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threesix
s
wordGraph.length>> 10
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threesixs
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threesixs
e
wordGraph.length>> 10
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threesixse
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threesixse
v
wordGraph.length>> 10
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threesixsev
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threesixsev
e
wordGraph.length>> 10
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threesixseve
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threesixseve
n
wordGraph.length>> 10
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> zero
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> one
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> two
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> three
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> four
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> five
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> six
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> seven
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> eight
isPerpectWord>>> threesixseven
isPerpectWord>>> wordGraph[i][0]>> nine
temp>>>>> threesixseven
answer>>> 3
테스트 4
입력값 〉 "123"
기댓값 〉 123
실행 결과 〉 실행한 결괏값 0이 기댓값 123과 다릅니다.
출력 〉 1
2
3
answer>>>
function solution(s) {
var answer = "";
let temp = "";
for(word of s){
// console.log(isNaN(word))
console.log(word);
// console.log(isNaN(word*1));
if(isNaN(word*1)){//문자인 경우
temp += word;
// console.log("tt");
temp,answer= isPerpectWord(temp,answer);
console.log("temp>>>>>",temp);
}else{//숫자인경우
if(isEmptyArr(temp)){
answer+=word;
}
}
function isPerpectWord(temp,answer){
let wordGraph = [["zero",0],["one",1],["two",2],["three",3],["four",4],["five",5],["six",6],["seven",7],["eight",8],["nine",9]];
console.log("wordGraph.length>> ",wordGraph.length)
for(let i=0; i<wordGraph.length; i++){
console.log("isPerpectWord>>> ",temp);
console.log("isPerpectWord>>> wordGraph[i][0]>>",wordGraph[i][0]);
if(temp == wordGraph[i][0]){
answer += wordGraph[i][1];
temp = "";
}
}//end for
}
}//for end
console.log("answer>>> ",answer);
return answer*1;
}
function isEmptyArr(arr) {
if(Array.isArray(arr) && arr.length === 0) {
return true;
}
return false;
}