Recursion을 이용한 순차탐색 - Node.js

프동프동·2022년 7월 1일
0

알고리즘 - Node.js

목록 보기
35/116
post-thumbnail
function search(data, begin, end, target) {
  if (begin > end) {
    return -1;
  }
  if (target === data[begin]) {
    return begin;
  } else {
    return search(data, begin + 1, end, target);
  }
}

console.log(search([5, 3, 2, 6, 1], 0, 4, 6));
profile
좋은 개발자가 되고싶은

0개의 댓글