题解 | #判断是否符合 USD 格式#
判断是否符合 USD 格式
https://www.nowcoder.com/practice/667dd00250d04d06989ed1b69102c9ab
let flag = false let arr = str.split('.')[0] let arrIs = str.split('.')[1] || [] let array = arr.split(',') for (let i = 0; i < array.length; i++) { let str1 = array[i] if (i === 0 && str1.length <= 4 && str1.length !== 1 && str1[0] === '$') { flag = true } else if (str1.length !== 3 ) { flag = false } } if (arrIs.length === 0 && flag) { flag = true } else if (arrIs.length !== 2) flag = false return flag