---
# System prepended metadata

title: 7 kyu Filter the number 將字串中的數字篩選出來

---

# 7 kyu Filter the number 將字串中的數字篩選出來


暴力解，比較差的方法，先做一個數字的字串，再把字元一個一個比對
效率不好:時間複雜度應該是 O(n**2)兩層迴圈

```javascript=
var filterString = function(value) {
  let charArr = value.split('')
  let number = '0123456789'
  let newString = ''
  charArr.forEach( char => {
    if (number.includes(char)) {
      newString += char
    }
  })
  return Number(newString)
}

```