1일차 (21/07/15)
등수구하기
let answer = [...new Array(arr.length)].map((item) => 1);
let check = 1;
while (true) {
if (check > arr.length) {
break;
}
const max = Math.max(...arr);
const currentCheck = check;
arr.forEach((arrItem, index) => {
if (max === arrItem) {
answer[index] = currentCheck;
arr[index] = -1;
check++;
}
});
}
점수계산
function solution(arr) {
let answer = 0;
let check = 1;
arr.forEach((item) => {
if (item === 0) {
check = 1;
} else {
answer += check;
check++;
}
});
return answer;
}
회문문자열
const string = s.toLowerCase();
const first = string.slice(0, string.length / 2);
let second;
if (string.length % 2 === 1) {
second = string.slice(string.length / 2 + 1);
}
if (string.length % 2 === 0) {
second = string.slice(string.length / 2);
}
for (let i = 0; i < first.length; i++) {
if (first[i] !== second[second.length - 1 - i]) {
return "NO";
}
}
return "YES";