알고리즘(Algorithm)

프로그래머스 - 크기가 작은 부분문자열[JS]

Hun-bot 2022. 12. 23. 21:19
728x90
반응형

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring

 

String.prototype.substring() - JavaScript | MDN

The substring() method returns the part of the string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied.

developer.mozilla.org

 

function solution(t, p) {
  let pLen=p.length;
  let tLen=t.length;
  let sliceStr=t
  let res=[]
  for(let i=0; i < tLen-pLen+1; i++) {
    res.push(sliceStr.substring(i,pLen+i))
  }
  res=res.filter((i)=>(Number(i)<=Number(p)))
  return res.length
}
728x90
반응형