JavaScript对称数字金字塔(机考)
let inputArray = [2,4,3] let result = '' let len = inputArray.length for(let i = 0;i < len;i++){ let el = inputArray[i] let resultV = getData(el) document.write(resultV + '<br/>') // result += `${resultV}\r`; } // console.log(result) function kong(n){ let res = '' for(let i = 0;i < n;i++){ res += ' ' } return res } function mid(n){ let res = '' for(let i = 0;i <= n;i++){ res += i.toString() } return res } function rig(n){ let res = '' for(let i = n;i > 0;i--){ res += i.toString() } return res } function getData(n){ let res = '' let i = 1 while(i <= n){ let k = kong(n - i), m = mid(i) r = rig(i - 1) res += `${k}${m}${r}<br/>` //document.write(res + '<br/>') i++ } return res }