[알고리즘] 숫자 문자열과 영단어 문제풀이(자바스크립트 javascript)
(풀기 전에 알아야 할 것) 1. replace(/a/g, b) : a를 b로 바꿔라 👌 zero : 0 ~ nine : 9 이므로 일단, 영어일 때 숫자로 바꿔줄 수 있는 replace 함수를 쭉 쓴다. s = s.replace(/zero/g,0 ) s = s.replace(/one/g,1 ) s = s.replace(/two/g,2 ) s = s.replace(/three/g,3 ) s = s.replace(/four/g,4 ) s = s.replace(/five/g,5 ) s = s.replace(/six/g,6 ) s = s.replace(/seven/g,7 ) s = s.replace(/eight/g,8 ) s = s.replace(/nine/g,9 ) 👌 지금 s는 문자열이다. 숫자로 바꿔줘야..
2022. 7. 21.
[알고리즘] 모의고사 문제풀이(자바스크립트 javascript)
👌 반복되는 모양이 있어서 변수부터 지정해주면 let a1 = [1, 2, 3, 4, 5]; let a2 = [2, 1, 2, 3, 2, 4, 2, 5] let a3 = [ 3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; 👌 filter 함수를 통해 answers 와 일치하는 개수를 꺼내주기, 이건 변수를 a1c, a2c, a3c 처럼 지정 let a1c = answers.filter((a,i)=> a === a1[i%a1.length]).length; let a2c = answers.filter((a,i)=> a === a2[i%a2.length]).length; let a3c = answers.filter((a,i)=> a === a3[i%a3.length]).length; 👌 이 세 변수 중..
2022. 7. 20.