// https://programmers.co.kr/learn/courses/30/lessons/12919
//seoul은 길이 1 이상, 1000 이하인 배열입니다.
//seoul의 원소는 길이 1 이상, 20 이하인 문자열입니다.
let seoul = ["Jane", "Kim"];
let result = solution(seoul);
console.log(result);
let result2 = findKim(seoul);
console.log(result2);
// include boolean 반환
//`The word "${word}" ${sentence.includes(word) ? 'is' : 'is not'} in the sentence`
// 문자열.match(찾을 단어)
//indexOf 는 찾은 값의 첫번째 원소의 위치를 반환해주며, 없을경우 -1을 리턴합니다.
//indexOf는... 배열에서 위치를 찾는구나..
function solution(seoul) {
var answer = '';
let pos = 0;
seoul.forEach(function (element, index) {
// console.log(element);
if (element == 'Kim') {
pos = index;
}
});
answer = `김서방은 ${pos}에 있다`;
return answer;
}
function findKim(seoul) {
var idx = seoul.indexOf('Kim');//배열도 된다?
return "김서방은 " + idx + "에 있다";
}
글씨를 찾는 거다.
문자열 기준 | 배열을 대상으로 위치 |
== | 배열.indexOf(문자열) 찾는 값의 첫번째 위치 반환, 없을경우 -1을 리턴
|
include
boolean 반환 `The word "${word}" ${sentence.includes(word) ? 'is' : 'is not'} in the sentence`
|
|
match
문자열.match(찾을 단어) |
|
|
'알고리즘 > 알고리즘' 카테고리의 다른 글
leetcode.com/problems/first-bad-version/ (0) | 2022.08.04 |
---|---|
[프로그래머스] 크레인 인형 뽑기 게임 (0) | 2022.04.08 |
[릿코드] twoSome (0) | 2022.03.15 |
[스킬 체크 테스트 Level.1] 실패율, 두개뽑아서더하기 (0) | 2022.03.08 |
[ 스킬 체크 테스트 Level.1] 직사각형 별찍기, 다트게임 (0) | 2022.03.07 |