"commit한 메시지"# Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.## Date: Mon Sep 4 15:33:01 2023 +0900## On branch main# Your branch is up to date with 'origin/main'.## Changes to be committed:# modified: ~# modified: ~# modified: ~# modified: ~# modified: ~# modified: ~# modified: ~# modified: ~# new file: ~#
메시지 수정 후 esc, :wq를 순서대로 입력해서 수정하는 창을 닫으면 된다.
2. 오래된 commit을 수정하는 경우
command line에 git log를 입력하면 로그를 볼 수 있다.
commit ~ (HEAD -> main)
Author: ~
Date: Mon Sep 4 15:33:01 2023 +0900
About 디자인 변경
commit ~
Author: ~
Date: Sun Sep 3 19:49:19 2023 +0900
디자인 수정
commit ~
Author: ~
Date: Sat Sep 2 00:17:20 2023 +0900
반응형 수정
commit ~
Author: ~
Date: Fri Sep 1 23:31:20 2023 +0900
About 파트 디자인 변경
:
위에서 두 번째 commit을 수정해야 한다면 다음과 같이 입력하면 가장 최근의 commit 2개를 보여준다.
git rebase -i HEAD~2
# HEAD~n -> head에서 n번째 메시지 수정
pick e05b90d 디자인 수정
pick 5808bb7 About 디자인 변경
# Rebase 418234b..5808bb7 onto 418234b (2 commands)## Commands:# p, pick <commit> = use commit# r, reword <commit> = use commit, but edit the commit message# e, edit <commit> = use commit, but stop for amending# s, squash <commit> = use commit, but meld into previous commit# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous# commit's log message, unless -C is used, in which case# keep only this commit's message; -c is same as -C but# opens the editor# x, exec <command> = run command (the rest of the line) using shell# b, break = stop here (continue rebase later with 'git rebase --continue')# d, drop <commit> = remove commit# l, label <label> = label current HEAD with a name# t, reset <label> = reset HEAD to a label# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]# create a merge commit using the original merge commit's# message (or the oneline, if no original merge commit was
.git/rebase-merge/git-rebase-todo [unix] (15:59 04/09/2023) 1,1 Top
<eact/portfolio/.git/rebase-merge/git-rebase-todo" [unix] 33L, 1547B
수정하고 싶은 commit 옆의 pick을 reword로 바꾼 후, esc, :wq를 순서대로 입력하면, commit을 수정할 수 있는 창이 뜬다.
메시지를 수정한 후, 똑같이 esc, :wq를 입력하여 저장해주면 된다.
이미 push가 끝난 commit을 수정하는 경우
위에서 commit 메시지 수정이 끝났다면, 다음과 같이 입력한다.
git push "리모트 이름""브랜치" --force
수정한 메시지를 force를 통해 강제로 push하는 방법이다.
force는 최대한 사용하지 않는 게 좋으니 commit message는 꼭! 한번 더 확인한 후 push하자.
숫자로 이루어진 문자열 t와 p가 주어질 때, t에서 p와 길이가 같은 부분문자열 중에서, 이 부분문자열이 나타내는 수가 p가 나타내는 수보다 작거나 같은 것이 나오는 횟수를 return하는 함수 solution을 완성하세요.
예를 들어, t="3141592"이고 p="271" 인 경우, t의 길이가 3인 부분 문자열은 314, 141, 415, 159, 592입니다. 이 문자열이 나타내는 수 중 271보다 작거나 같은 수는 141, 159 2개 입니다.
제한 사항
1 ≤ p의 길이 ≤ 18
p의 길이 ≤ t의 길이 ≤ 10,000
t와 p는 숫자로만 이루어진 문자열이며, 0으로 시작하지 않습니다.
ex)
t: "3141592"
p: "271"
result: 2
나의 solution
functionsolution(t, p) {
// answer 배열 생성var answer = [];
for(let i=0; i<t.length; i++) {
var ele = t.slice(i, i+p.length)
// 배열에 들어갈 ele의 길이는 p의 길이와 같고 ele의 값은 p보다 작거나 같아야 한다if(ele.length===p.length && ele<=p) answer.push(ele)
}
// 배열의 길이를 리턴return answer.length
}
Description
1. slice 메소드를 사용하면 간단하게 해결할 수 있다.
// slice 메소드는 배열의 begin index부터 end index까지(end index는 포함x)에 대한 복사본을 새로운 배열로 반환한다.
array = ['world','earth','sun','moon','mars']
console.log(array.slice(2));
// ['sun','moon','mars']console.log(array.slice(2, 4));
// Expected output: Array ['sun','moon']console.log(array.slice(-2));
// Expected output: Array ['moon','mars']console.log(array.slice(2, -1));
// Expected output: Array ['sun','moon']
헷갈릴 수도 있는 splice 메소드는 아래와 같다.
// splice 메소드는 원본 배열에서 새로운 요소를 추가, 삭제, 교체하여 새로운 배열을 리턴한다.
array = ['world','earth','sun','moon','mars']
// 삭제(시작 index가 음수일 경우 뒤에서부터 요소를 센다)
array.splice(2, 1) // index 2부터 1개의 요소 제거console.log(array) // ['world','earth','moon','mars']// 추가
array.splice(2,0,'venus')
console.log(array) // ['world','earth','venus','sun','moon','mars']
2. 문자열 t를 i 인덱스부터 i+p.length 인덱스까지 잘라 변수 ele에 할당한다.
3. ele의 길이가 p의 길이와 같고 ele의 값이 p보다 작거나 같으면 answer 배열에 추가한다.
PC 환경에서는 내 위치를 제대로 잡지 못하지만, 모바일 환경에서는 정확하게 잡는 편이다.
// kakaoScript.js
...
const getCurrentPos = () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function (position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
// 내 현재 위치를 kakao map에 표시한다.var currentPos = new kakao.maps.LatLng(lat, lon);
var marker = new kakao.maps.Marker({
map: map,
position: currentPos,
image: new kakao.maps.MarkerImage(
"https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/markerStar.png",
new kakao.maps.Size(24, 35),
{ offset: new kakao.maps.Point(13, 35) }
)
});
map.setCenter(currentPos);
},
// 위치를 가져올 수 없는 경우, 카카오 본사로 위치를 잡는다.function (err) {
options.center = new kakao.maps.LatLng(37.566826, 126.9786567);
const map = new kakao.maps.Map(container, options);
})
}
}
getCurrentPos();
...
두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환하는 함수, solution을 완성해 보세요. 배열의 맨 앞에 최대공약수, 그다음 최소공배수를 넣어 반환하면 됩니다. 예를 들어 두 수 3, 12의 최대공약수는 3, 최소공배수는 12이므로 solution(3, 12)는 [3, 12]를 반환해야 합니다.
제한 사항
두 수는 1이상 1000000이하의 자연수입니다.
ex)
n: 3, m: 12, return [3, 12]
최대 공약수: 두 수 n, m의 공통된 약수 중에서 가장 큰 수
최소 공배수: 두 수 n, m의 공통된 배수 중에서 가장 작은 수
이 문제를 풀기 위해서는 다음과 같은 원리를 이용할 수 있다.
- 유클리드 호제법
- num1 * num2 = gcd * lcm
유클리드 호제법
1. n>m일 때, 큰 수(n)를 작은 수(m)로 나눈다. (n % m = R1)
2. 나누는 수 m을 나눈 나머지 R1로 나눈다. (m % R1 = R2)
3. R1을 R2로 나눈다. (R1 % R2 = R3)
이 과정을 반복해서 Rn이 0이 된다면 나누는 수(Rn-1)가 최대공약수이다.
Answer
functionsolution(n, m) {
const gcd = (a, b) => a%b === 0 ? b : gcd(b, a%b);
const lcm = (a, b) => (a*b) / gcd(a,b);
return [gcd(n,m), lcm(n,m)]
}