From 1a65cf3fe41d79a6e3c175296a941d57a0f51073 Mon Sep 17 00:00:00 2001 From: Tymur Date: Fri, 3 Apr 2026 10:14:30 +0300 Subject: [PATCH] Solution --- src/arrayMethodSort.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index 32363d0d..5cd4ea83 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -4,8 +4,22 @@ * Implement method Sort */ function applyCustomSort() { - [].__proto__.sort2 = function(compareFunction) { - // write code here + [].__proto__.sort2 = function (compareFunction) { + for (let i = 0; i < this.length - 1; i++) { + for (let j = 0; j < this.length - 1 - i; j++) { + const a = this[j].toString(); + const b = this[j + 1].toString(); + + if (compareFunction ? compareFunction(a, b) > 0 : a > b) { + const temp = this[j]; + + this[j] = this[j + 1]; + this[j + 1] = temp; + } + } + } + + return this; }; }