From 64c86659aaf21398381bf33620eada87eb775226 Mon Sep 17 00:00:00 2001 From: Daria Chakhalian Date: Sun, 28 Jun 2026 20:51:24 +0300 Subject: [PATCH] Solution --- src/arrayMethodSort.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index 32363d0d..425f6686 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -4,8 +4,24 @@ * Implement method Sort */ function applyCustomSort() { - [].__proto__.sort2 = function(compareFunction) { - // write code here + [].__proto__.sort2 = function ( + compareFunction = (a, b) => + String(a) > String(b) ? 1 : String(a) < String(b) ? -1 : 0, + ) { + for (let i = 0; i < this.length - 1; i++) { + for (let j = 0; j < this.length - i - 1; j++) { + const element = this[j]; + + if (compareFunction(this[j], this[j + 1]) > 0) { + this[j] = this[j + 1]; + this[j + 1] = element; + } else { + continue; + } + } + } + + return this; }; }