From ca1d7bafdedade9b8500087551c4674d3a82dece Mon Sep 17 00:00:00 2001 From: Dazavrrr Date: Wed, 6 May 2026 14:16:09 +0300 Subject: [PATCH] solution --- src/arrayMethodSort.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index 32363d0d..6946a28c 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -4,8 +4,23 @@ * Implement method Sort */ function applyCustomSort() { - [].__proto__.sort2 = function(compareFunction) { - // write code here + [].__proto__.sort2 = function (compareFunction) { + for (let i = 0; i < this.length; i++) { + for (let j = 0; j < this.length - 1; j++) { + const temp = this[j]; + + const shouldSwap = compareFunction + ? compareFunction(this[j], this[j + 1]) > 0 + : String(this[j]) > String(this[j + 1]); + + if (shouldSwap) { + this[j] = this[j + 1]; + this[j + 1] = temp; + } + } + } + + return this; }; }