Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: reverseString #272

Closed
1 of 2 tasks
ssi02014 opened this issue Jun 27, 2024 · 0 comments · Fixed by #323
Closed
1 of 2 tasks

[Feature]: reverseString #272

ssi02014 opened this issue Jun 27, 2024 · 0 comments · Fixed by #323
Assignees
Labels
feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils

Comments

@ssi02014
Copy link
Contributor

ssi02014 commented Jun 27, 2024

Package Scope

  • 기존 패키지에 기능 추가
  • 새로운 패키지
  • Package name: @modern-kit/utils/string

Overview

문자를 뒤집는 reverseString 함수를 추가합니다.

console.log(reverseString("hello")); // "olleh"

과도한 성능을 고려해서 복잡한 코드를 통해 가독성을 해치기보다, 가독성도 챙기며 동시에 유효하지 않은 유니코드 사용시 문제를 개선할 수 있는 spread - reverse - join 형태로 구현합니다.

참고로 split() + reverse()'foo 𝌆 bar' 와 같은 케이스에서 문제가 있습니다.

('foo 𝌆 bar').split("").reverse().join(""); // rab �� oof
// "𝌆" 가 사라졌습니다 😣

spread 연산자를 사용하면 의도대로 동작합니다

[...('foo 𝌆 bar')].reverse().join(""); // 'rab 𝌆 oof'

Note

https://stackoverflow.com/questions/958908/how-do-you-reverse-a-string-in-place

@ssi02014 ssi02014 added feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils labels Jun 27, 2024
@Sangminnn Sangminnn self-assigned this Jul 1, 2024
@ssi02014 ssi02014 linked a pull request Jul 11, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 새로운 기능 추가 @modern-kit/utils @modern-kit/utils
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants