일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- 출처:구멍가게코딩단-코배스(개정판)
- boolean배열
- form.getImageFies 오타났음
- 행열. 2중반복문..
- 생활코딩
- 그럼 int배열의 deefault값은?????
- 마지막에 배열의 foreach구문이 틀린것같은데 ...... 저게왜틀린건지나는잘모르겠슴다.
- (참고로 boolean 배열의 default 값은 false 이다.
- ㅓㅂ
- bindingresult 쓰니까 에러났다. 어떻게해야하냐;;
- while문이 틀린이유?? math.random()을 사용해서푸는법?
- Today
- Total
푸린세스
Capitalize Exercise : 문자열함수 slice(), substring() 본문
const str = 'Mozilla';
console.log(str.substring(1, 3));
// Expected output: "oz"
console.log(str.substring(2));
// Expected output: "zilla"
Capitalize ExerciseDefine a function called capitalize that accepts a string argument and returns a new string with the first letter capitalized (but the rest of the string unchanged). For example:
- capitalize('eggplant') // "Eggplant"
- capitalize('pamplemousse') // "Pamplemousse"
- capitalize('squid') //"Squid"
Hints:
- Remember that strings are immutable, meaning that you cannot simply change the first letter in the original string. You will need to make a new string that you return.
- Single out the first letter and capitalize it. (use a string method to help!)
- Add that first letter to the rest of the original string, sliced to omit the original first letter (use a string method to help!)
- For example: 'eggplant' becomes 'E' + 'ggplant'
// DEFINE YOUR FUNCTION BELOW:
function capitalize(str){
let result = '';
for(let i=1; i<str.length; i++){
result += str[i];
}
return str[0].toUpperCase() + result;
}
function capitalize(word) {
return word[0].toUpperCase() + word.slice(1); // == word.substring(1);
// return `${word[0].toUpperCase()}${word.slice(1)}`; ==> 템플릿 리터럴
}
console.log(capitalize('eggplant'));
console.log(capitalize('pamplemousse'));
console.log(capitalize('squid'));
문자열함수 slice(), substring() 를 이용해서 푸심
내가 쓰는방법과다름
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Array.prototype.slice() - JavaScript | MDN
slice() 메서드는 어떤 배열의 begin 부터 end 까지(end 미포함)에 대한 얕은 복사본을 새로운 배열 객체로 반환합니다. 원본 배열은 바뀌지 않습니다.
developer.mozilla.org
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/substring
String.prototype.substring() - JavaScript | MDN
substring() 메소드는 string 객체의 시작 인덱스로 부터 종료 인덱스 전 까지 문자열의 부분 문자열을 반환합니다.
developer.mozilla.org
String.prototype.slice()
slice() 메소드는 문자열의 일부를 추출하면서 새로운 문자열을 반환합니다
const str = 'The quick brown fox jumps over the lazy dog.';
console.log(str.slice(31));
// Expected output: "the lazy dog."
console.log(str.slice(4, 19));
// Expected output: "quick brown fox"
console.log(str.slice(-4));
// Expected output: "dog."
console.log(str.slice(-9, -5));
// Expected output: "lazy"
String.prototype.substring()
substring() 메소드는 string 객체의 시작 인덱스로 부터 종료 인덱스 전 까지 문자열의 부분 문자열을 반환합니다.
const str = 'Mozilla';
console.log(str.substring(1, 3));
// Expected output: "oz"
console.log(str.substring(2));
// Expected output: "zilla"
'프론트 > 자바스크립트' 카테고리의 다른 글
고차함수 2 리턴값이 함수인경우. (0) | 2023.05.30 |
---|---|
자바스크립트 정리-1 삼중등호 vs 이중등호 (0) | 2023.05.25 |