문자열 슬라이싱
def solution(phone_number):
star = "*" * len(phone_number[0:-4])
return star + phone_number[-4:]
function solution(phone_number) {
let star = ""
const starLen = phone_number.slice(0, -4).length;
for(var i=0; i<starLen; i++){
star += "*"
}
return star + phone_number.slice(-4);
}
python 슬라이싱
phone_number = "01012345678"
phone_number[0:-4]
# "0101234"
phone_number[-4:]
# 5678
js 슬라이싱
const a = "0123456789"
a.slice(0,8)
// "01234567"
a.slice(8)
// "89"
a.slice(0, -5)
// "01234"
a.slice(-5)
// "56789"
a.slice(-5, 9)
// "5678"
a.slice(5, -1)
// "5678"
a.slice(5, -2)
// "567"
a.slice(5, -4)
// "5"
a.slice(5, -5)
// ""