> 기초/코테 연습
TIL-2024.03.21 - 코테연습 - 옹알이(1) & 명예의전달(1).programmers
Janku
2024. 3. 21. 20:46

URL:
https://school.programmers.co.kr/learn/courses/30/lessons/133499
// URL > https://school.programmers.co.kr/learn/courses/30/lessons/133499
const solution = (babbling) => {
const ableBabblingArray = [ "aya", "ye", "woo", "ma" ];
for (let i = 0; i < babbling.length; i++) {
for( let j = 0; j < ableBabblingArray.length ; j ++){
if(babbling[i].includes(ableBabblingArray[j].repeat(2))) {
break;
}
babbling[i] = babbling[i].split(ableBabblingArray[j]).join('!');
}
}
return babbling.filter(e => {
return /(^!+$)/.test(e)
}).length;
};
// console.log("result:: ", solution([ "aya", "yee", "u", "maa" ])); // 1
console.log("result:: ", solution([ "ayaye", "uuu", "yeye", "yemawoo", "ayaayaa" ])); // 2
URL:
https://school.programmers.co.kr/learn/courses/30/lessons/138477?language=javascript
// URL > https://school.programmers.co.kr/learn/courses/30/lessons/138477?language=javascript
const solution = (k, score) => {
const resultArr = [];
return score.map((item , index)=> {
resultArr.push(item);
resultArr.sort((a,b) => b - a);
if(resultArr.length > k ){
resultArr.pop()
}
return resultArr[resultArr.length-1]
})
}
console.log("result:: ", solution(3, [ 10, 100, 20, 150, 1, 100, 200 ]));
// console.log("result:: ", solution(4, [ 0, 300, 40, 300, 20, 70, 150, 50, 500, 1000 ]));