Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ohveloper
problemSolving
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
problemSolving
/
createPhoneNum.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
30 lines (28 loc) · 1.86 KB
main
Breadcrumbs
problemSolving
/
createPhoneNum.js
Copy path
Top
File metadata and controls
Code
Blame
30 lines (28 loc) · 1.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function createPhoneNumber(arr) {
// 각각의 변수값을 생성해서 해당 요소들을 담아둔다
// head = (010) <- arr의 길이가 8 일때 맨앞에 달아둔다
let head = '(010)' // 주의할점 head 변수는 바뀔수 있기 때문에 let 을 이용한다
// arr의 n번째 인덱스를 구하기 위해 arr.length 값을 미리 변수에 담아둔다
const len = arr.length
// first = arr 의 -8번째 요소부터 -4번째 요소까지 담는다
// 문자열이 아닌 붙어있는 문자열로 받기위해 join('') 메소드를 통해 값을 받는다
const first = arr.slice(len - 8, len - 4).join('')
// last = arr 의 -4번째 요소부터 번째 요소까지 담는다
// 마지막 요소는 arr.length 값 -1 이고 slice 메소드를 사용할시에 자신의 바로 앞전 수까지의 값을 가르키기 떄문에
// len 값은 8 이지만 8-1 이되면서 7번째 인덱스까지를 받아오게 된다
const last = arr.slice(len - 4, len).join('')
// 함수내 변수 선언이 8자리를 기준으로 하기때문에 if 문은 11자리가 아닐때 해당 함수내 변수를 전부다
// 리턴하는 방식으로 코드를 짠다면 수월할 것이다
// 11자리 일땐 head 의 값만 바꿔준후 똑같이 리턴한다
// arr의 길이가 11일때
// head 값을 변경해준다 => arr의 0번째부터 2번째 요소로
if (len === 11) {
// 이전 head 의 변수값이 '(010)' 으로 완성이 되어있기 때문에 바뀐 head 의 값도 같은 방식으로 만들어져있어야 리턴값을 한꺼번에 조종할수 있다
head = `(${arr.slice(0, 3).join('')})`
// slice 메소드는 해당입력값의 앞전까지만 불러온다
}
//
// head + first + last
return `${head}${first}-${last}`
}
// ohveloper 2020.DEC.16
You can’t perform that action at this time.