diff --git a/5.4ArrayMethod/t.js b/5.4ArrayMethod/t.js index 26a63cc..a0d43af 100644 --- a/5.4ArrayMethod/t.js +++ b/5.4ArrayMethod/t.js @@ -34,4 +34,18 @@ console.log(someUsers); // arr.map(fn) let lengths = array.map(item=>item.length); -alert(lengths); \ No newline at end of file +console.log(lengths); + +// arr.sort(fn) +function compare(a, b){ + if (a > b) return 1; + if (a == b) return 0; + if (a < b) return -1; +} + +arr = [15, 2 ,1]; +console.log(`arr.sort(): ${arr.sort(compare)}`); +console.log(`arr.sort(): ${arr.sort((a,b) => a - b)}`); + +let countries = ['Österreich', 'Andorra', 'Vietnam']; +console.log(countries.sort((a,b) => a.localeCompare(b))) \ No newline at end of file