From 9b6e7ba456f2937c7ae11b35afbcda6daf3be0ec Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 29 Jan 2026 23:09:31 +0200 Subject: [PATCH 1/7] start --- .github/workflows/test.yml-template | 23 +++++++++++++++++++++++ package-lock.json | 9 +++++---- package.json | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test.yml-template diff --git a/.github/workflows/test.yml-template b/.github/workflows/test.yml-template new file mode 100644 index 00000000..bb13dfc4 --- /dev/null +++ b/.github/workflows/test.yml-template @@ -0,0 +1,23 @@ +name: Test + +on: + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/package-lock.json b/package-lock.json index eadb3115..84d432db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "license": "GPL-3.0", "devDependencies": { "@mate-academy/eslint-config": "latest", - "@mate-academy/scripts": "^1.8.6", + "@mate-academy/scripts": "^2.1.3", "eslint": "^8.57.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-node": "^11.1.0", @@ -1467,10 +1467,11 @@ } }, "node_modules/@mate-academy/scripts": { - "version": "1.8.6", - "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-1.8.6.tgz", - "integrity": "sha512-b4om/whj4G9emyi84ORE3FRZzCRwRIesr8tJHXa8EvJdOaAPDpzcJ8A0sFfMsWH9NUOVmOwkBtOXDu5eZZ00Ig==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-2.1.3.tgz", + "integrity": "sha512-a07wHTj/1QUK2Aac5zHad+sGw4rIvcNl5lJmJpAD7OxeSbnCdyI6RXUHwXhjF5MaVo9YHrJ0xVahyERS2IIyBQ==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/rest": "^17.11.2", "@types/get-port": "^4.2.0", diff --git a/package.json b/package.json index 9c0b7bbd..0827621b 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "license": "GPL-3.0", "devDependencies": { "@mate-academy/eslint-config": "latest", - "@mate-academy/scripts": "^1.8.6", + "@mate-academy/scripts": "^2.1.3", "eslint": "^8.57.0", "eslint-plugin-jest": "^28.6.0", "eslint-plugin-node": "^11.1.0", From caa947e6378312eb7b8a5b5aac4015a4791c67a4 Mon Sep 17 00:00:00 2001 From: pavlo Date: Fri, 30 Jan 2026 15:21:13 +0200 Subject: [PATCH 2/7] create function --- src/arrayMethodSort.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index 32363d0d..3ad54553 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; i++) { + for (let j = 0; j < this.length - 1; j++) { + const res = compareFunction(this[j], this[j + 1]); + + if (res > 0) { + const buf = this[j]; + + this[j] = this[j + 1]; + + this[j + 1] = buf; + } + } + } + + return this; }; } From db21fba7b6072334d755eba61584471b182e970c Mon Sep 17 00:00:00 2001 From: pavlo Date: Sat, 31 Jan 2026 15:52:11 +0200 Subject: [PATCH 3/7] tests passed --- src/arrayMethodSort.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index 3ad54553..8a5337ef 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -5,15 +5,17 @@ */ function applyCustomSort() { [].__proto__.sort2 = function (compareFunction) { + const input = + compareFunction || ((a, b) => (String(a) > String(b) ? 1 : -1)); + for (let i = 0; i < this.length; i++) { - for (let j = 0; j < this.length - 1; j++) { - const res = compareFunction(this[j], this[j + 1]); + for (let j = 0; j < this.length - 1 - i; j++) { + const res = input(this[j], this[j + 1]); if (res > 0) { const buf = this[j]; this[j] = this[j + 1]; - this[j + 1] = buf; } } From 5d3f83e858e70ba26e990782478c939140709827 Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 12 Feb 2026 23:29:41 +0200 Subject: [PATCH 4/7] updated code --- src/arrayMethodSort.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index 8a5337ef..2e679b71 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -6,7 +6,14 @@ function applyCustomSort() { [].__proto__.sort2 = function (compareFunction) { const input = - compareFunction || ((a, b) => (String(a) > String(b) ? 1 : -1)); + compareFunction || + ((a, b) => { + if (String(a) === String(b)) { + return 0; + } else { + return String(a) > String(b) ? 1 : -1; + } + }); for (let i = 0; i < this.length; i++) { for (let j = 0; j < this.length - 1 - i; j++) { @@ -25,4 +32,8 @@ function applyCustomSort() { }; } +Array.prototype.sort = function (compareFunction) { + return [].__proto__.sort2.call(this, compareFunction); +}; + module.exports = applyCustomSort; From 194b37abd838fcced228a5eb0a0971af9c666952 Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 12 Feb 2026 23:42:55 +0200 Subject: [PATCH 5/7] changed comparing --- src/arrayMethodSort.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index 2e679b71..d250eee3 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -8,11 +8,12 @@ function applyCustomSort() { const input = compareFunction || ((a, b) => { - if (String(a) === String(b)) { - return 0; - } else { - return String(a) > String(b) ? 1 : -1; - } + const A = String(a); + const B = String(b); + + if (A === B) return 0; + + return A > B ? 1 : -1; }); for (let i = 0; i < this.length; i++) { From 2d1e7087391f2d11f5e54df4e4b90490e5a0733e Mon Sep 17 00:00:00 2001 From: pavlo Date: Thu, 12 Feb 2026 23:45:53 +0200 Subject: [PATCH 6/7] added comment --- src/arrayMethodSort.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index d250eee3..f0c0fcf6 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -11,7 +11,9 @@ function applyCustomSort() { const A = String(a); const B = String(b); - if (A === B) return 0; + if (A === B) { + return 0; + } return A > B ? 1 : -1; }); @@ -33,6 +35,7 @@ function applyCustomSort() { }; } +// eslint-disable-next-line no-extend-native Array.prototype.sort = function (compareFunction) { return [].__proto__.sort2.call(this, compareFunction); }; From ee8a77c08a6d921518e7f55d4b175580611f8c68 Mon Sep 17 00:00:00 2001 From: pavlo Date: Fri, 13 Feb 2026 02:46:12 +0200 Subject: [PATCH 7/7] moved prototype into the end method --- src/arrayMethodSort.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/arrayMethodSort.js b/src/arrayMethodSort.js index f0c0fcf6..3084d300 100644 --- a/src/arrayMethodSort.js +++ b/src/arrayMethodSort.js @@ -33,11 +33,11 @@ function applyCustomSort() { return this; }; -} -// eslint-disable-next-line no-extend-native -Array.prototype.sort = function (compareFunction) { - return [].__proto__.sort2.call(this, compareFunction); -}; + // eslint-disable-next-line no-extend-native + Array.prototype.sort = function (compareFunction) { + return [].__proto__.sort2.call(this, compareFunction); + }; +} module.exports = applyCustomSort;