diff --git "a/yujin-level0/Week39/\352\270\200\354\236\220 \354\235\264\354\226\264 \353\266\231\354\227\254 \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.js" "b/yujin-level0/Week39/\352\270\200\354\236\220 \354\235\264\354\226\264 \353\266\231\354\227\254 \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.js" new file mode 100644 index 0000000..22d7c55 --- /dev/null +++ "b/yujin-level0/Week39/\352\270\200\354\236\220 \354\235\264\354\226\264 \353\266\231\354\227\254 \353\254\270\354\236\220\354\227\264 \353\247\214\353\223\244\352\270\260.js" @@ -0,0 +1,13 @@ +function solution(my_string, index_list) { + let result = ""; + for(let i = 0; i < index_list.length; i++) { + a = index_list[i] + result += my_string[a]; + } + return result; +} + +// 다른 풀이 +function solution(my_string, index_list) { + return index_list.map(i => my_string[i]).join('') +} \ No newline at end of file diff --git "a/yujin-level0/Week39/\353\254\270\354\236\220\354\227\264 \353\202\264 p\354\231\200 y\354\235\230 \352\260\234\354\210\230.js" "b/yujin-level0/Week39/\353\254\270\354\236\220\354\227\264 \353\202\264 p\354\231\200 y\354\235\230 \352\260\234\354\210\230.js" new file mode 100644 index 0000000..a3b330e --- /dev/null +++ "b/yujin-level0/Week39/\353\254\270\354\236\220\354\227\264 \353\202\264 p\354\231\200 y\354\235\230 \352\260\234\354\210\230.js" @@ -0,0 +1,19 @@ +function solution(s) { + let count = 0; + for (const char of s.toUpperCase()) { + if (char === 'P') count++; + else if (char === 'Y') count--; + } + return count === 0; +} + +// 다른 풀이 +function solution(s) { + const upperS = s.toUpperCase(); + // 각각의 개수를 변수에 담아 비교하면 가독성이 훨씬 좋아짐! + const pCount = upperS.split("P").length - 1; + const yCount = upperS.split("Y").length - 1; + // 만일 p가 2개면 + + return pCount === yCount; +} \ No newline at end of file diff --git "a/yujin-level0/Week39/\354\240\221\353\221\220\354\202\254\354\235\270\354\247\200 \355\231\225\354\235\270\355\225\230\352\270\260.js" "b/yujin-level0/Week39/\354\240\221\353\221\220\354\202\254\354\235\270\354\247\200 \355\231\225\354\235\270\355\225\230\352\270\260.js" new file mode 100644 index 0000000..1ee03b6 --- /dev/null +++ "b/yujin-level0/Week39/\354\240\221\353\221\220\354\202\254\354\235\270\354\247\200 \355\231\225\354\235\270\355\225\230\352\270\260.js" @@ -0,0 +1,4 @@ +function solution(my_string, is_prefix) { + // boolean 앞에 + 해주면 true는 1, false는 0으로 변환 + return +my_string.startsWith(is_prefix); +} \ No newline at end of file