From 2499aee177d442b8e528961eca442048387d8cd7 Mon Sep 17 00:00:00 2001 From: melarkkkk Date: Sun, 28 Dec 2025 19:36:50 +0100 Subject: [PATCH 1/2] add task solution --- src/arrayReverse.test.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/arrayReverse.test.js b/src/arrayReverse.test.js index cf8ac47..12afd49 100644 --- a/src/arrayReverse.test.js +++ b/src/arrayReverse.test.js @@ -1,4 +1,5 @@ 'use strict'; +/* eslint-disable max-len */ describe(`Function 'arrayReverse':`, () => { const arrayReverse = require('./arrayReverse'); @@ -8,13 +9,41 @@ describe(`Function 'arrayReverse':`, () => { }); it(`should return an array`, () => { + const res = arrayReverse(['a']); + expect(res).toBeInstanceOf(Array); + }); + + it(`should reverse an array + of the words consists of Latin letters, + numbers and special symbols`, () => { + const array1 = ['Mate', 'Academy']; + const res1 = ['ymed', 'acAetaM']; + const array2 = ['1,2,', '22!']; + const res2 = ['!22,', '2,1']; + const array3 = ['QWErty', '#$%~^']; + const res3 = ['^~%$#y', 'trEWQ']; + + expect(arrayReverse(array1)).toEqual(res1); + expect(arrayReverse(array2)).toEqual(res2); + expect(arrayReverse(array3)).toEqual(res3); + }); + + it(`should keep the length of the strings from the original array`, () => { + const array = ['1', '22', '333', '4444']; + const res = ['4', '44', '433', '3221']; + + expect(arrayReverse(array)).toEqual(res); }); it(`should return an empty string if original array consists of an empty string`, () => { - expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']); - }); + const array1 = ['', 'Mate', '', 'academy']; + const array2 = ['', 'Mate', '', 'academy']; + const res1 = ['', 'ymed', '', 'acaetaM']; + const res2 = ['', 'ymed', '', 'acaetaM']; - // write more tests here + expect(arrayReverse(array1)).toEqual(res1); + expect(arrayReverse(array2)).toEqual(res2); + }); }); From 57b8fd512d305e9f8c515e12277b0a9a8047b499 Mon Sep 17 00:00:00 2001 From: melarkkkk Date: Sun, 28 Dec 2025 19:45:43 +0100 Subject: [PATCH 2/2] feat: add additional tests --- src/arrayReverse.test.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/arrayReverse.test.js b/src/arrayReverse.test.js index 12afd49..d0b5020 100644 --- a/src/arrayReverse.test.js +++ b/src/arrayReverse.test.js @@ -14,6 +14,13 @@ describe(`Function 'arrayReverse':`, () => { expect(res).toBeInstanceOf(Array); }); + it('should return an empty array if the original one is empty', () => { + const array = []; + const res = []; + + expect(arrayReverse(array)).toEqual(res); + }); + it(`should reverse an array of the words consists of Latin letters, numbers and special symbols`, () => { @@ -23,25 +30,31 @@ describe(`Function 'arrayReverse':`, () => { const res2 = ['!22,', '2,1']; const array3 = ['QWErty', '#$%~^']; const res3 = ['^~%$#y', 'trEWQ']; + const array4 = ['Hell0']; + const res4 = ['0lleH']; expect(arrayReverse(array1)).toEqual(res1); expect(arrayReverse(array2)).toEqual(res2); expect(arrayReverse(array3)).toEqual(res3); + expect(arrayReverse(array4)).toEqual(res4); }); it(`should keep the length of the strings from the original array`, () => { - const array = ['1', '22', '333', '4444']; - const res = ['4', '44', '433', '3221']; + const array1 = ['1', '22', '333', '4444']; + const res1 = ['4', '44', '433', '3221']; + const array2 = ['I', 'am', 'a', 'student!']; + const res2 = ['!', 'tn', 'e', 'dutsamaI']; - expect(arrayReverse(array)).toEqual(res); + expect(arrayReverse(array1)).toEqual(res1); + expect(arrayReverse(array2)).toEqual(res2); }); it(`should return an empty string if original array consists of an empty string`, () => { const array1 = ['', 'Mate', '', 'academy']; - const array2 = ['', 'Mate', '', 'academy']; + const array2 = ['', '', '']; const res1 = ['', 'ymed', '', 'acaetaM']; - const res2 = ['', 'ymed', '', 'acaetaM']; + const res2 = ['', '', '']; expect(arrayReverse(array1)).toEqual(res1); expect(arrayReverse(array2)).toEqual(res2);