题解 | #字符串反转#
字符串排序
http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
let len; while ((len = readline())) { const tempArr = []; const reg = new RegExp(/[a-zA-Z]/); for (let i = 0; i < +len; i++) { let str = readline(); if (reg.test(str)) { tempArr.push(str); } } function compare(a, b) { if (a > b) return true; else return false; }
function exchange(arr, a, b) { let temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; }
function sort(arr) { if (arr == null || arr.length == 0) return []; for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length - i - 1; j++) { if (compare(arr[j], arr[j + 1])) { exchange(arr, j, j + 1); } } } } sort(tempArr); tempArr.forEach((item) => { console.log(item); }); }