diff --git a/staff/ventura-rodriguez/biblio/.gitignore b/staff/ventura-rodriguez/biblio/.gitignore new file mode 100644 index 00000000..f8610813 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/.gitignore @@ -0,0 +1,2 @@ +pnpm-lock.yaml +/node_modules/ \ No newline at end of file diff --git a/staff/ventura-rodriguez/biblio/at.js b/staff/ventura-rodriguez/biblio/at.js new file mode 100644 index 00000000..6dea6d0e --- /dev/null +++ b/staff/ventura-rodriguez/biblio/at.js @@ -0,0 +1,17 @@ +/** + * Retrieves the element at the specified index in the Biblio instance. + * + * @param {number} _index - The index of the element to retrieve. + * @returns {*} The element at the specified index, or undefined if the index is out of bounds.   + + */ +function at(_index) { + if (!(typeof _index === "number")) return this[0]; + if (this.length < Math.abs(_index)) return undefined; + + const index = _index >= 0 ? _index : this.length + _index; + + return this[index]; +} + +module.exports = at; diff --git a/staff/ventura-rodriguez/biblio/at.test.js b/staff/ventura-rodriguez/biblio/at.test.js new file mode 100644 index 00000000..2c41046e --- /dev/null +++ b/staff/ventura-rodriguez/biblio/at.test.js @@ -0,0 +1,28 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("At method", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + + it("Use at method returning value of a reasonable index", () => { + const resultBiblio = biblio.at(3); + const resultArray = array.at(3); + expect(resultBiblio).to.be.equal(resultArray); + }); + it("Use at for not positive value", () => { + const resultBiblio = biblio.at(-2); + const resultArray = array.at(-2); + expect(resultBiblio).to.be.equal(resultArray); + }); + it("Use at for out of range index", () => { + const resultBiblio = biblio.at(20); + const resultArray = array.at(20); + expect(resultBiblio).to.be.equal(resultArray); + }); + it("Use at for out of range index non positive case", () => { + const resultBiblio = biblio.at(-30); + const resultArray = array.at(-30); + expect(resultBiblio).to.be.equal(resultArray); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/concat.js b/staff/ventura-rodriguez/biblio/concat.js new file mode 100644 index 00000000..496bbd1a --- /dev/null +++ b/staff/ventura-rodriguez/biblio/concat.js @@ -0,0 +1,28 @@ +const Biblio = require("./contructor"); + +/** + * Concatenates the current Biblio instance with the provided arguments. + * + * @param {...Biblio|*} args - The elements or Biblio instances to concatenate. + * @returns {Biblio} A new Biblio instance containing the concatenated elements. + */ +function concat() { + const result = new Biblio(); + while (result.length < this.length) { + result[result.length] = this[result.length]; + result.length++; + } + + for (let i = 0; i < arguments.length; i++) { + let element = arguments[i]; + if (!(element instanceof Biblio)) element = new Biblio(element); + for (let j = 0; j < element.length; j++) { + result[result.length] = element[j]; + result.length++; + } + } + + return result; +} + +module.exports = concat; diff --git a/staff/ventura-rodriguez/biblio/concat.test.js b/staff/ventura-rodriguez/biblio/concat.test.js new file mode 100644 index 00000000..39e958ef --- /dev/null +++ b/staff/ventura-rodriguez/biblio/concat.test.js @@ -0,0 +1,38 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Concat method", () => { + const array = [1, 2]; + const biblio = new Biblio(1, 2); + + it("Use concat with only one Biblio parameter", () => { + const resultArray = array.concat([3, 4]); + const resultBiblio = biblio.concat(new Biblio(3, 4)); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio.length).to.be.equal(array.length).to.be.equal(2); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(4); + }); + + it("Use concat with only one not Biblio parameter", () => { + const resultArray = array.concat("foo"); + const resultBiblio = biblio.concat("foo"); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio.length).to.be.equal(array.length).to.be.equal(2); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(3); + }); + + it("Use concat with only nultiple and mixed types parameters", () => { + const resultArray = array.concat([3, 4], [5, 6], Infinity); + const resultBiblio = biblio.concat( + new Biblio(3, 4), + new Biblio(5, 6), + Infinity + ); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio.length).to.be.equal(array.length).to.be.equal(2); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(7); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/contructor.js b/staff/ventura-rodriguez/biblio/contructor.js new file mode 100644 index 00000000..2f04f3ae --- /dev/null +++ b/staff/ventura-rodriguez/biblio/contructor.js @@ -0,0 +1,21 @@ +/** + * Creates an instance of `Biblio`, representing an array-like object with a `length` property. + * + * The `Biblio` constructor calculates the length based on the number of arguments passed + * and assigns each argument to the instance as array-like properties. + * + * @constructor + * @param {...*} value - Any number of values to be stored in the `Biblio` instance as array-like properties. + * @property {number} length - The number of arguments passed to the constructor. + */ +function Biblio() { + let _length = 0; + while (arguments[_length] !== undefined) _length++; + this.length = _length; + + for (let i = 0; i < arguments.length; i++) { + this[i] = arguments[i]; + } +} + +module.exports = Biblio; diff --git a/staff/ventura-rodriguez/biblio/contructor.test.js b/staff/ventura-rodriguez/biblio/contructor.test.js new file mode 100644 index 00000000..549e84c3 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/contructor.test.js @@ -0,0 +1,36 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Constructor", function () { + describe("", () => { + let biblioInstance; + + beforeEach(() => { + biblioInstance = new Biblio(1, "two", true); + }); + + it("Should calculate the correct length of arguments", () => { + expect(biblioInstance.length).to.equal(3); + }); + + it("Should store each argument as an indexed property", () => { + expect(biblioInstance[0]).to.equal(1); + expect(biblioInstance[1]).to.equal("two"); + expect(biblioInstance[2]).to.equal(true); + }); + }); + + it("Should handle no arguments correctly", () => { + const emptyBiblio = new Biblio(); + expect(emptyBiblio.length).to.equal(0); + }); + + it("Should allow various data types as arguments", () => { + const mixedBiblio = new Biblio(42, { key: "value" }, [1, 2, 3], null); + expect(mixedBiblio.length).to.equal(4); + expect(mixedBiblio[0]).to.equal(42); + expect(mixedBiblio[1]).to.deep.equal({ key: "value" }); + expect(mixedBiblio[2]).to.deep.equal([1, 2, 3]); + expect(mixedBiblio[3]).to.equal(null); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/copy-within.js b/staff/ventura-rodriguez/biblio/copy-within.js new file mode 100644 index 00000000..c5f6e8c4 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/copy-within.js @@ -0,0 +1,31 @@ +const Biblio = require("./contructor"); + +/** + * Copies a sequence of elements from one position to another within the Biblio instance. + * + * @param {number} _target - The index of the starting position of the replacement. + * @param {number} _start - The index of the beginning of the sequence to copy. + * @param {number} _end - The index of the end of the sequence to copy (exclusive). + * @returns {Biblio} The modified Biblio instance. + */ +function copyWithin(_target, _start, _end = this.length) { + const elementsToCopy = new Biblio(); + + const target = _target >= 0 ? _target : this.length + _target; + const start = _start >= 0 ? _start : this.length + _start; + const end = _end >= 0 ? _end : this.length + _end; + + let i = 0; + while (elementsToCopy.length < end - start) { + elementsToCopy[i] = this[start + i]; + elementsToCopy.length += 1; + i++; + } + + for (let i = 0; i < elementsToCopy.length; i++) + this[target + i] = elementsToCopy[i]; + + return this; +} + +module.exports = copyWithin; diff --git a/staff/ventura-rodriguez/biblio/copy-within.test.js b/staff/ventura-rodriguez/biblio/copy-within.test.js new file mode 100644 index 00000000..c705ca67 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/copy-within.test.js @@ -0,0 +1,40 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("CopyWithin method", () => { + it("Use copyWithin using target and start parameters with reasonable values", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.copyWithin(0, 5); + const resultBiblio = biblio.copyWithin(0, 5); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(8); + expect(biblio).to.be.deep.equal(resultBiblio); + }); + + it("Use copyWithin using all parameters with reasonable values", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.copyWithin(0, 3, 4); + const resultBiblio = biblio.copyWithin(0, 3, 4); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(8); + expect(biblio).to.be.deep.equal(resultBiblio); + }); + + it("Use copyWithin using all parameters with negative values", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.copyWithin(-2, -3, -1); + const resultBiblio = biblio.copyWithin(-2, -3, -1); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(8); + expect(biblio).to.be.deep.equal(resultBiblio); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/every.js b/staff/ventura-rodriguez/biblio/every.js new file mode 100644 index 00000000..da5f5ab2 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/every.js @@ -0,0 +1,19 @@ +/** + * Checks if all elements in the Biblio instance pass the provided test function. + * + * @param {function} callback - The callback function to test each element against. + * @returns {boolean} True if all elements pass the test, false otherwise. + */ +function every(callback) { + let result = true; + + let i = 0; + while (i < this.length && result) { + if (!callback(this[i])) result = false; + i++; + } + + return result; +} + +module.exports = every; diff --git a/staff/ventura-rodriguez/biblio/every.test.js b/staff/ventura-rodriguez/biblio/every.test.js new file mode 100644 index 00000000..6524e408 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/every.test.js @@ -0,0 +1,21 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Every method", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + + it("Use every evaluating each typeof every element with reasonable values", () => { + const resultArray = array.every((item) => typeof item === "number"); + const resultBiblio = biblio.every((item) => typeof item === "number"); + expect(resultBiblio).to.be.equal(resultArray).to.be.true; + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); + + it("Use every evaluating if every element is 4 number", () => { + const resultArray = array.every((item) => item === 4); + const resultBiblio = biblio.every((item) => item === 4); + expect(resultBiblio).to.be.equal(resultArray).to.be.false; + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/fill.js b/staff/ventura-rodriguez/biblio/fill.js new file mode 100644 index 00000000..72d8afcb --- /dev/null +++ b/staff/ventura-rodriguez/biblio/fill.js @@ -0,0 +1,18 @@ +/** + * Fills all elements of the Biblio instance with the specified value. + * + * @param {*} value - The value to fill the elements with. + * @param {number} _start - The index to start filling from. + * @param {number} _end - The index to stop filling at (exclusive). + * @returns {Biblio} The modified Biblio instance. + */ +function fill(value, _start = 0, _end = this.length) { + const start = _start >= 0 ? _start : this.length + _start; + const end = _end >= 0 ? _end : this.length + _end; + + for (let i = start; i < end; i++) this[i] = value; + + return this; +} + +module.exports = fill; diff --git a/staff/ventura-rodriguez/biblio/fill.test.js b/staff/ventura-rodriguez/biblio/fill.test.js new file mode 100644 index 00000000..948ff220 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/fill.test.js @@ -0,0 +1,48 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Fill method", () => { + it("Use fill with reasonable value parameter", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.fill(6); + const resultBiblio = biblio.fill(6); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio).to.be.deep.equal(resultBiblio); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); + + it("Use fill with value and start parameters with reasonable values", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.fill(5, 1); + const resultBiblio = biblio.fill(5, 1); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio).to.be.deep.equal(resultBiblio); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); + + it("Use fill with all parameters with reasonable values", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.fill(0, 2, 4); + const resultBiblio = biblio.fill(0, 2, 4); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio).to.be.deep.equal(resultBiblio); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); + + it("Use fill with all parameters with negative values", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.fill(4, -3, -2); + const resultBiblio = biblio.fill(4, -3, -2); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(biblio).to.be.deep.equal(resultBiblio); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/filter.js b/staff/ventura-rodriguez/biblio/filter.js new file mode 100644 index 00000000..864260fe --- /dev/null +++ b/staff/ventura-rodriguez/biblio/filter.js @@ -0,0 +1,22 @@ +const Biblio = require("./contructor"); + +/** + * Filters the elements of the Biblio instance based on the provided callback function. + * + * @param {function} callback - The callback function to test each element against. + * @returns {Biblio} A new Biblio instance containing the elements that passed the test. + */ +function filter(callback) { + let result = new Biblio(); + + for (let i = 0; i < this.length; i++) { + const element = this[i]; + if (callback(element)) { + result[result.length] = element; + result.length += 1; + } + } + + return result; +} +module.exports = filter; diff --git a/staff/ventura-rodriguez/biblio/filter.test.js b/staff/ventura-rodriguez/biblio/filter.test.js new file mode 100644 index 00000000..d96ea38b --- /dev/null +++ b/staff/ventura-rodriguez/biblio/filter.test.js @@ -0,0 +1,27 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Filter method", () => { + const array = [1, 2, 3, 4, "a", "b", "c", "d", "e"]; + const biblio = new Biblio(1, 2, 3, 4, "a", "b", "c", "d", "e"); + + it("Use filter passing each element of the array as a parameter of the callback function to be filtered by typeof operator", () => { + const resultArray = array.filter((item) => typeof item === "number"); + const resultBiblio = biblio.filter((item) => typeof item === "number"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(4); + }); + + it("Use filter passing each element of the array as a parameter of the callback function to be filtered by typeof operator", () => { + const resultArray = array.filter((item) => typeof item === "string"); + const resultBiblio = biblio.filter((item) => typeof item === "string"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(5); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/find-index.js b/staff/ventura-rodriguez/biblio/find-index.js new file mode 100644 index 00000000..88f85216 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/find-index.js @@ -0,0 +1,19 @@ +/** + * Finds the index of the first element in the Biblio instance that passes the provided test function. + * + * @param {function} callback - The callback function to test each element against. + * @returns {number} The index of the first element that passes the test, or -1 if no element passes the test. + */ +function findIndex(callback) { + let foundIndex = -1; + + let i = 0; + do { + if (callback(this[i])) foundIndex = i; + else i++; + } while (foundIndex < 0 && i < this.length); + + return foundIndex; +} + +module.exports = findIndex; diff --git a/staff/ventura-rodriguez/biblio/find-index.test.js b/staff/ventura-rodriguez/biblio/find-index.test.js new file mode 100644 index 00000000..ecc88ab2 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/find-index.test.js @@ -0,0 +1,23 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("FindIndex method", () => { + const array = [1, 2, 3, 4, "a", "b", "c", "b", "e"]; + const biblio = new Biblio(1, 2, 3, 4, "a", "b", "c", "b", "e"); + + it('Use findIndex passing each element of the array as a parameter of the callback function to find index of "b"', () => { + const resultArray = array.findIndex((item) => item === "b"); + const resultBiblio = biblio.findIndex((item) => item === "b"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(5); + }); + + it("Use findIndex passing each element of the array as a parameter of the callback function to search by typeof operator", () => { + const resultArray = array.findIndex((item) => typeof item === "boolean"); + const resultBiblio = biblio.findIndex((item) => typeof item === "boolean"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(-1); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/find-last.js b/staff/ventura-rodriguez/biblio/find-last.js new file mode 100644 index 00000000..e52c4b0c --- /dev/null +++ b/staff/ventura-rodriguez/biblio/find-last.js @@ -0,0 +1,19 @@ +/** + * Finds the last element in the Biblio instance that passes the provided test function. + * + * @param {function} callback - The callback function to test each element against. + * @returns {*} The last element that passes the test, or undefined if no element passes the test. + */ +function findLast(callback) { + let foundIndex = -1; + + let i = this.length; + do { + if (callback(this[i])) foundIndex = i; + else i--; + } while (foundIndex < 0 && i >= 0); + + return this[foundIndex]; +} + +module.exports = findLast; diff --git a/staff/ventura-rodriguez/biblio/find-last.test.js b/staff/ventura-rodriguez/biblio/find-last.test.js new file mode 100644 index 00000000..ec73ec92 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/find-last.test.js @@ -0,0 +1,23 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("FindLast method", () => { + const array = [1, 2, 3, 4, "a", "b", "c", "b", "e"]; + const biblio = new Biblio(1, 2, 3, 4, "a", "b", "c", "b", "e"); + + it('Use findLast passing each element of the array as a parameter of the callback function to find index of "b"', () => { + const resultArray = array.findLast((item) => item === "b"); + const resultBiblio = biblio.findLast((item) => item === "b"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal("b"); + }); + + it("Use findLast passing each element of the array as a parameter of the callback function to search by typeof operator", () => { + const resultArray = array.findLast((item) => typeof item === "boolean"); + const resultBiblio = biblio.findLast((item) => typeof item === "boolean"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + expect(resultBiblio).to.be.equal(resultArray).to.be.undefined; + }); +}); diff --git a/staff/ventura-rodriguez/biblio/find.js b/staff/ventura-rodriguez/biblio/find.js new file mode 100644 index 00000000..b8051665 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/find.js @@ -0,0 +1,19 @@ +/** + * Finds the first element in the Biblio instance that passes the provided test function. + * + * @param {function} callback - The callback function to test each element against. + * @returns {*} The first element that passes the test, or undefined if no element passes the test. + */ +function find(callback) { + let foundIndex = -1; + + let i = 0; + do { + if (callback(this[i])) foundIndex = i; + else i++; + } while (foundIndex < 0 && i < this.length); + + return this[foundIndex]; +} + +module.exports = find; diff --git a/staff/ventura-rodriguez/biblio/find.test.js b/staff/ventura-rodriguez/biblio/find.test.js new file mode 100644 index 00000000..9467a727 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/find.test.js @@ -0,0 +1,23 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Find method", () => { + const array = [1, 2, 3, 4, "a", "b", "c", "b", "e"]; + const biblio = new Biblio(1, 2, 3, 4, "a", "b", "c", "b", "e"); + + it('Use find passing each element of the array as a parameter of the callback function to find index of "b"', () => { + const resultArray = array.find((item) => item === "b"); + const resultBiblio = biblio.find((item) => item === "b"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal("b"); + }); + + it("Use find passing each element of the array as a parameter of the callback function to search by typeof operator", () => { + const resultArray = array.find((item) => typeof item === "boolean"); + const resultBiblio = biblio.find((item) => typeof item === "boolean"); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + expect(resultBiblio).to.be.equal(resultArray).to.be.undefined; + }); +}); diff --git a/staff/ventura-rodriguez/biblio/flat.optional.js b/staff/ventura-rodriguez/biblio/flat.optional.js new file mode 100644 index 00000000..f2297154 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/flat.optional.js @@ -0,0 +1,28 @@ +const Biblio = require("./contructor"); + +/** + * Creates a new Biblio instance with all sub-biblio elements concatenated up to the specified depth. + * + * @param {number} depth - The depth up to which to flatten nested biblios (default: 1). + * @returns {Biblio} A new Biblio instance containing the flattened elements. + */ +function flat(depth = 1) { + const result = new Biblio(); + + for (let i = 0; i < this.length; i++) { + if (this[i] instanceof Biblio && depth) { + const res = flat.call(this[i], depth - 1); + for (let j = 0; j < res.length; j++) { + result[result.length] = res[j]; + result.length += 1; + } + } else { + result[result.length] = this[i]; + result.length += 1; + } + } + + return result; +} + +module.exports = flat; diff --git a/staff/ventura-rodriguez/biblio/flat.optional.test.js b/staff/ventura-rodriguez/biblio/flat.optional.test.js new file mode 100644 index 00000000..c61190c0 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/flat.optional.test.js @@ -0,0 +1,69 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Flat method", () => { + it("Use flat without any parameter", () => { + const array = [0, 1, 2, [3, 4]]; + const biblio = new Biblio(0, 1, 2, new Biblio(3, 4)); + const resultArray = array.flat(); + const resultBiblio = biblio.flat(); + expect(biblio.length).to.be.equal(array.length).to.be.equal(4); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(5); + }); + + it("Use flat without any parameter and multiple biblio levels", () => { + const array = [0, 1, [2, [3, [4, 5]]]]; + const biblio = new Biblio( + 0, + 1, + new Biblio(2, new Biblio(3, new Biblio(4, 5))) + ); + const resultArray = array.flat(); + const resultBiblio = biblio.flat(); + expect(biblio.length).to.be.equal(array.length).to.be.equal(3); + expect(resultBiblio[0]).to.be.equal(0); + expect(resultBiblio[1]).to.be.equal(1); + expect(resultBiblio[2]).to.be.equal(2); + expect(resultBiblio[3]).to.be.deep.equal(new Biblio(3, new Biblio(4, 5))); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(4); + }); + + it("Use flat with depth parameter and multiple biblio levels", () => { + const array = [0, 1, [2, [3, [4, 5]]]]; + const biblio = new Biblio( + 0, + 1, + new Biblio(2, new Biblio(3, new Biblio(4, 5))) + ); + const resultArray = array.flat(2); + const resultBiblio = biblio.flat(2); + expect(biblio.length).to.be.equal(array.length).to.be.equal(3); + expect(resultBiblio[0]).to.be.equal(0); + expect(resultBiblio[1]).to.be.equal(1); + expect(resultBiblio[2]).to.be.equal(2); + expect(resultBiblio[3]).to.be.equal(3); + expect(resultBiblio[4]).to.be.deep.equal(new Biblio(4, 5)); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(5); + }); + + it("Use flat with Infinity as depth value parameter and multiple biblio levels", () => { + const array = [0, 1, [2, [3, [4, 5]]]]; + const biblio = new Biblio( + 0, + 1, + new Biblio(2, new Biblio(3, new Biblio(4, 5))) + ); + const resultArray = array.flat(Infinity); + const resultBiblio = biblio.flat(Infinity); + expect(biblio.length).to.be.equal(array.length).to.be.equal(3); + expect(resultBiblio[0]).to.be.equal(0); + expect(resultBiblio[1]).to.be.equal(1); + expect(resultBiblio[2]).to.be.equal(2); + expect(resultBiblio[3]).to.be.equal(3); + expect(resultBiblio[4]).to.be.equal(4); + expect(resultBiblio[5]).to.be.equal(5); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(6); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/for-each.js b/staff/ventura-rodriguez/biblio/for-each.js new file mode 100644 index 00000000..19a2b4a0 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/for-each.js @@ -0,0 +1,11 @@ +/** + * Calls the provided callback function once for each element in the Biblio instance. + * + * @param {function} callback - The callback function to execute for each element. + * @returns {void} + */ +function forEach(callback) { + for (let i = 0; i < this.length; i++) callback(this[i], i, this); +} + +module.exports = forEach; diff --git a/staff/ventura-rodriguez/biblio/for-each.test.js b/staff/ventura-rodriguez/biblio/for-each.test.js new file mode 100644 index 00000000..7ffc6316 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/for-each.test.js @@ -0,0 +1,14 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("ForEach method", () => { + it("Use forEach passing each element, index and biblio as a parameters of the callback function", () => { + const biblio = new Biblio(1, 2, 3); + const array = [1, 2, 3]; + biblio.forEach((element, index, biblio) => { + expect(element).to.be.equal(array[index]); + expect(biblio).to.be.deep.equal(new Biblio(1, 2, 3)); + }); + expect(biblio).to.be.deep.equal(new Biblio(1, 2, 3)); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/includes.js b/staff/ventura-rodriguez/biblio/includes.js new file mode 100644 index 00000000..35c95f1d --- /dev/null +++ b/staff/ventura-rodriguez/biblio/includes.js @@ -0,0 +1,19 @@ +/** + * Checks if the Biblio instance includes the specified element. + * + * @param {*} searchElement - The element to search for. + * @param {number} [fromIndex=0] - The index to start searching from. + * @returns {boolean} True if the element is found, false otherwise. + */ +function includes(searchElement, fromIndex = 0) { + let result = false; + let i = fromIndex; + do { + if (this[i] === searchElement) result = true; + i++; + } while (i < this.length && !result); + + return result; +} + +module.exports = includes; diff --git a/staff/ventura-rodriguez/biblio/includes.test.js b/staff/ventura-rodriguez/biblio/includes.test.js new file mode 100644 index 00000000..29791e33 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/includes.test.js @@ -0,0 +1,28 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Includes method", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + + it("Use includes with searchElement parameter", () => { + const resultArray = array.includes(4); + const resultBiblio = biblio.includes(4); + expect(biblio).to.be.deep.equal(new Biblio(1, 2, 3, 4, 5, 6, 7, 8)); + expect(resultBiblio).to.be.equal(resultArray); + }); + + it("Use includes with searchElement and fromIndex parameters", () => { + const resultArray = array.includes(3, 5); + const resultBiblio = biblio.includes(3, 5); + expect(biblio).to.be.deep.equal(new Biblio(1, 2, 3, 4, 5, 6, 7, 8)); + expect(resultBiblio).to.be.equal(resultArray); + }); + + it("Use includes passing NaN as searchElement parameter", () => { + const resultArray = array.includes(NaN); + const resultBiblio = biblio.includes(NaN); + expect(biblio).to.be.deep.equal(new Biblio(1, 2, 3, 4, 5, 6, 7, 8)); + expect(resultBiblio).to.be.equal(resultArray); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/index-of.js b/staff/ventura-rodriguez/biblio/index-of.js new file mode 100644 index 00000000..58c4cf0b --- /dev/null +++ b/staff/ventura-rodriguez/biblio/index-of.js @@ -0,0 +1,20 @@ +/** + * Finds the index of the first occurrence of the specified element in the Biblio instance. + * + * @param {*} searchElement - The element to search for. + * @param {number} [fromIndex=0] - The index to start searching from. + * @returns {number} The index of the first occurrence of the element, or -1 if not found. + */ +function indexOf(searchElement, fromIndex = 0) { + let result = -1; + let i = fromIndex; + + do { + if (searchElement === this[i]) result = i; + i++; + } while (i < this.length && result === -1); + + return result; +} + +module.exports = indexOf; diff --git a/staff/ventura-rodriguez/biblio/index-of.test.js b/staff/ventura-rodriguez/biblio/index-of.test.js new file mode 100644 index 00000000..fbb50aef --- /dev/null +++ b/staff/ventura-rodriguez/biblio/index-of.test.js @@ -0,0 +1,34 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("IndexOf method", () => { + const array = ["ant", "bison", "camel", "duck", "bison"]; + const biblio = new Biblio("ant", "bison", "camel", "duck", "bison"); + + it("Use indexOf with searchElement parameter", () => { + const resultArray = array.indexOf("bison"); + const resultBiblio = biblio.indexOf("bison"); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison") + ); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(1); + }); + + it("Use indexOf with searchElement and fromIndex parameters", () => { + const resultArray = array.indexOf("bison", 2); + const resultBiblio = biblio.indexOf("bison", 2); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison") + ); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(4); + }); + + it("Use indexOf with searchElement parameter with not match value", () => { + const resultArray = array.indexOf("giraffe"); + const resultBiblio = biblio.indexOf("giraffe"); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison") + ); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(-1); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/index.js b/staff/ventura-rodriguez/biblio/index.js new file mode 100644 index 00000000..a40d1453 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/index.js @@ -0,0 +1,50 @@ +const Biblio = require("./contructor.js"); +const at = require("./at.js"); +const concat = require("./concat.js"); +const copyWithin = require("./copy-within.js"); +const every = require("./every.js"); +const fill = require("./fill.js"); +const filter = require("./filter.js"); +const findIndex = require("./find-index.js"); +const findLast = require("./find-last.js"); +const find = require("./find.js"); +const flat = require("./flat.optional.js"); +const forEach = require("./for-each.js"); +const includes = require("./includes.js"); +const indexOf = require("./index-of.js"); +const map = require("./map.js"); +const pop = require("./pop.js"); +const push = require("./push.js"); +const reduce = require("./reduce.js"); +const reverse = require("./reverse.js"); +const shift = require("./shift.js"); +const slice = require("./slice.js"); +const some = require("./some.js"); +const sort = require("./sort.js"); +const splice = require("./splice.js"); + +Biblio.prototype.at = at; +Biblio.prototype.concat = concat; +Biblio.prototype.copyWithin = copyWithin; +Biblio.prototype.every = every; +Biblio.prototype.fill = fill; +Biblio.prototype.filter = filter; +Biblio.prototype.findIndex = findIndex; +Biblio.prototype.findLast = findLast; +Biblio.prototype.find = find; +Biblio.prototype.flat = flat; +Biblio.prototype.forEach = forEach; +Biblio.prototype.includes = includes; +Biblio.prototype.indexOf = indexOf; +Biblio.prototype.map = map; +Biblio.prototype.pop = pop; +Biblio.prototype.push = push; +Biblio.prototype.reduce = reduce; +Biblio.prototype.reverse = reverse; +Biblio.prototype.shift = shift; +Biblio.prototype.slice = slice; +Biblio.prototype.some = some; +Biblio.prototype.sort = sort; +Biblio.prototype.splice = splice; + +module.exports = Biblio; diff --git a/staff/ventura-rodriguez/biblio/index.test.js b/staff/ventura-rodriguez/biblio/index.test.js new file mode 100644 index 00000000..e0a294a5 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/index.test.js @@ -0,0 +1,25 @@ +describe("Biblio testing", function () { + require("./contructor.test.js"); + require("./at.test.js"); + require("./concat.test.js"); + require("./copy-within.test.js"); + require("./every.test.js"); + require("./fill.test.js"); + require("./filter.test.js"); + require("./find-index.test.js"); + require("./find-last.test.js"); + require("./flat.optional.test.js"); + require("./for-each.test.js"); + require("./includes.test.js"); + require("./index-of.test.js"); + require("./map.test.js"); + require("./pop.test.js"); + require("./push.test.js"); + require("./reduce.test.js"); + require("./reverse.test.js"); + require("./shift.test.js"); + require("./slice.test.js"); + require("./some.test.js"); + require("./sort.test.js"); + require("./splice.test.js"); +}); diff --git a/staff/ventura-rodriguez/biblio/map.js b/staff/ventura-rodriguez/biblio/map.js new file mode 100644 index 00000000..9d33ff66 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/map.js @@ -0,0 +1,21 @@ +const Biblio = require("./contructor"); + +/** + * Applies the provided callback function to each element of the Biblio instance and returns a new Biblio instance containing the results. + * + * @param {function} callback - The callback function to apply to each element. + * @returns {Biblio} A new Biblio instance containing the results of the callback. + */ +function map(callback) { + let result = new Biblio(); + + for (let i = 0; i < this.length; i++) { + result[i] = callback(this[i]); + } + + result.length = this.length; + + return result; +} + +module.exports = map; diff --git a/staff/ventura-rodriguez/biblio/map.test.js b/staff/ventura-rodriguez/biblio/map.test.js new file mode 100644 index 00000000..c25be8a2 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/map.test.js @@ -0,0 +1,23 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Map method", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + + it("Use map passing each element of the array as a parameter of the callback function to by multiply 2", () => { + const resultArray = array.map((item) => item * 2); + const resultBiblio = biblio.map((item) => item * 2); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(biblio.length).to.be.equal(8); + }); + + it("Use map passing each element of the array as a parameter of the callback function to by divide 2", () => { + const resultArray = array.map((item) => item % 2); + const resultBiblio = biblio.map((item) => item % 2); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(biblio.length).to.be.equal(8); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/package.json b/staff/ventura-rodriguez/biblio/package.json new file mode 100644 index 00000000..b1460558 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/package.json @@ -0,0 +1,17 @@ +{ + "name": "biblio", + "version": "0.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "mocha ./index.test.js", + "test-inspect": "mocha --inspect-brk ./index.test.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "chai": "4.5.0", + "mocha": "10.7.3" + } +} diff --git a/staff/ventura-rodriguez/biblio/pop.js b/staff/ventura-rodriguez/biblio/pop.js new file mode 100644 index 00000000..e5adfc97 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/pop.js @@ -0,0 +1,16 @@ +/** + * Removes and returns the last element from the Biblio instance. + * + * @returns {*} The removed element, or undefined if the Biblio instance is empty. + */ +function pop() { + if (this.length === 0) return undefined; + + let result = this[this.length - 1]; + delete this[this.length - 1]; + this.length = this.length - 1; + + return result; +} + +module.exports = pop; diff --git a/staff/ventura-rodriguez/biblio/pop.test.js b/staff/ventura-rodriguez/biblio/pop.test.js new file mode 100644 index 00000000..178a15b9 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/pop.test.js @@ -0,0 +1,16 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Pop method", () => { + const array = ["ant", "bison", "camel", "duck", "bison"]; + const biblio = new Biblio("ant", "bison", "camel", "duck", "bison"); + + it("Use pop with resonable biblio instance", () => { + const resultArray = array.pop(); + const resultBiblio = biblio.pop(); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck") + ); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal("bison"); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/push.js b/staff/ventura-rodriguez/biblio/push.js new file mode 100644 index 00000000..bab2d59f --- /dev/null +++ b/staff/ventura-rodriguez/biblio/push.js @@ -0,0 +1,18 @@ +/** + * Adds one or more elements to the end of the Biblio instance and returns the new length. + * + * @param {...*} elements - The elements to add. + * @returns {number} The new length of the Biblio instance. + */ +function push() { + for (let i = 0; i < arguments.length; i++) { + this[this.length] = arguments[i]; + this.length += 1; + } + + let result = this.length; + + return result; +} + +module.exports = push; diff --git a/staff/ventura-rodriguez/biblio/push.test.js b/staff/ventura-rodriguez/biblio/push.test.js new file mode 100644 index 00000000..6089466b --- /dev/null +++ b/staff/ventura-rodriguez/biblio/push.test.js @@ -0,0 +1,26 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Push method", () => { + it("Use push with one parameter", () => { + const array = ["ant", "bison", "camel", "duck", "bison"]; + const biblio = new Biblio("ant", "bison", "camel", "duck", "bison"); + const resultArray = array.push("snake"); + const resultBiblio = biblio.push("snake"); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison", "snake") + ); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(6); + }); + + it("Use push with multiple parameter", () => { + const array = ["ant", "bison", "camel", "duck", "bison"]; + const biblio = new Biblio("ant", "bison", "camel", "duck", "bison"); + const resultArray = array.push("snake", "gorilla"); + const resultBiblio = biblio.push("snake", "gorilla"); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison", "snake", "gorilla") + ); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(7); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/reduce.js b/staff/ventura-rodriguez/biblio/reduce.js new file mode 100644 index 00000000..09ce6303 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/reduce.js @@ -0,0 +1,18 @@ +/** + * Reduces the elements of the Biblio instance to a single value. + * + * @param {function} callbackFn - The callback function to apply to each element. + * @param {*} initialValue - The initial value of the accumulator. + * @returns {*} The reduced value. + */ +function reduce(callbackFn, initialValue = 0) { + let accumulator = initialValue; + + for (let i = 0; i < this.length; i++) { + accumulator = callbackFn(accumulator, this[i]); + } + + return accumulator; +} + +module.exports = reduce; diff --git a/staff/ventura-rodriguez/biblio/reduce.test.js b/staff/ventura-rodriguez/biblio/reduce.test.js new file mode 100644 index 00000000..3bf61166 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/reduce.test.js @@ -0,0 +1,17 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Reduce method", () => { + it("Use reduce to sum all values of biblio", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.reduce( + (accumulator, currentValue) => accumulator + currentValue + ); + const resultBiblio = biblio.reduce( + (accumulator, currentValue) => accumulator + currentValue + ); + expect(biblio).to.be.deep.equal(new Biblio(1, 2, 3, 4, 5, 6, 7, 8)); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal(36); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/reverse.js b/staff/ventura-rodriguez/biblio/reverse.js new file mode 100644 index 00000000..74357834 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/reverse.js @@ -0,0 +1,16 @@ +/** + * Reverses the order of elements in the Biblio instance. + * + * @returns {Biblio} The modified Biblio instance. + */ +function reverse() { + for (let i = 0; i < Math.floor(this.length / 2); i++) { + const elementSaved = this[this.length - 1 - i]; + this[this.length - 1 - i] = this[i]; + this[i] = elementSaved; + } + + return this; +} + +module.exports = reverse; diff --git a/staff/ventura-rodriguez/biblio/reverse.test.js b/staff/ventura-rodriguez/biblio/reverse.test.js new file mode 100644 index 00000000..d242ae57 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/reverse.test.js @@ -0,0 +1,15 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Reverse method", () => { + it("Should reverse elements of biblio", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + const resultArray = array.reverse(); + const resultBiblio = biblio.reverse(); + expect(biblio).to.be.equal(resultBiblio); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(8); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/shift.js b/staff/ventura-rodriguez/biblio/shift.js new file mode 100644 index 00000000..e5558ae2 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/shift.js @@ -0,0 +1,14 @@ +/** + * Removes the first element from the Biblio instance and returns it. + * + * @returns {*} The removed element, or undefined if the Biblio instance is empty. + */ +function shift() { + const element = this[0]; + for (let i = 1; i < this.length; i++) this[i - 1] = this[i]; + delete this[this.length - 1]; + this.length = this.length - 1; + return element; +} + +module.exports = shift; diff --git a/staff/ventura-rodriguez/biblio/shift.test.js b/staff/ventura-rodriguez/biblio/shift.test.js new file mode 100644 index 00000000..e05288f5 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/shift.test.js @@ -0,0 +1,16 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Shift method", () => { + const array = ["ant", "bison", "camel", "duck", "bison"]; + const biblio = new Biblio("ant", "bison", "camel", "duck", "bison"); + + it("Use shift with resonable biblio instance", () => { + const resultArray = array.shift(); + const resultBiblio = biblio.shift(); + expect(biblio).to.be.deep.equal( + new Biblio("bison", "camel", "duck", "bison") + ); + expect(resultBiblio).to.be.equal(resultArray).to.be.equal("ant"); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/slice.js b/staff/ventura-rodriguez/biblio/slice.js new file mode 100644 index 00000000..cdf9aef1 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/slice.js @@ -0,0 +1,24 @@ +const Biblio = require("./contructor"); + +/** + * Extracts a portion of the Biblio instance from the specified start index to the specified end index (exclusive). + * + * @param {number} _start - The index to start extracting from. + * @param {number} _end - The index to stop extracting at (exclusive). + * @returns {Biblio} A new Biblio instance containing the extracted elements. + */ +function slice(_start = 0, _end = this.length) { + const start = _start >= 0 ? _start : this.length + _start; + const end = _end >= 0 ? _end : this.length + _end; + + const result = new Biblio(); + + for (let index = start; index < end; index++) { + result[result.length] = this[index]; + result.length += 1; + } + + return result; +} + +module.exports = slice; diff --git a/staff/ventura-rodriguez/biblio/slice.test.js b/staff/ventura-rodriguez/biblio/slice.test.js new file mode 100644 index 00000000..93e9e5c2 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/slice.test.js @@ -0,0 +1,51 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Slice method", () => { + const array = ["ant", "bison", "camel", "duck", "bison"]; + const biblio = new Biblio("ant", "bison", "camel", "duck", "bison"); + + it("Use slice with start parameter", () => { + const resultArray = array.slice(2); + const resultBiblio = biblio.slice(2); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison") + ); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(3); + }); + + it("Use slice with start and end parameters", () => { + const resultArray = array.slice(2, 4); + const resultBiblio = biblio.slice(2, 4); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison") + ); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(2); + }); + + it("Use slice with not positive value as start parameter", () => { + const resultArray = array.slice(-2); + const resultBiblio = biblio.slice(-2); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison") + ); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(2); + }); + + it("Use slice with not positive value as end parameter", () => { + const resultArray = array.slice(2, -1); + const resultBiblio = biblio.slice(2, -1); + expect(biblio).to.be.deep.equal( + new Biblio("ant", "bison", "camel", "duck", "bison") + ); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(2); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/some.js b/staff/ventura-rodriguez/biblio/some.js new file mode 100644 index 00000000..09448591 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/some.js @@ -0,0 +1,18 @@ +/** + * Checks if at least one element in the Biblio instance passes the provided test function. + * + * @param {function} callback - The callback function to test each element against. + * @returns {boolean} True if at least one element passes the test, false otherwise. + */ +function some(callback) { + let result = false; + let i = 0; + while (i < this.length && !result) { + if (callback(this[i])) result = true; + i++; + } + + return result; +} + +module.exports = some; diff --git a/staff/ventura-rodriguez/biblio/some.test.js b/staff/ventura-rodriguez/biblio/some.test.js new file mode 100644 index 00000000..6a3eb5f1 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/some.test.js @@ -0,0 +1,22 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Every method", () => { + const array = [1, 2, 3, 4, 5, 6, 7, 8]; + const biblio = new Biblio(1, 2, 3, 4, 5, 6, 7, 8); + + it("Use some evaluating each typeof some element with reasonable values", () => { + const resultArray = array.some((item) => typeof item === "string"); + const resultBiblio = biblio.some((item) => typeof item === "string"); + expect(resultBiblio).to.be.equal(resultArray).to.be.false; + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); + + it("Use some evaluating if some element is 4 number", () => { + const resultArray = array.some((item) => item === 4); + const resultBiblio = biblio.some((item) => item === 4); + expect(resultBiblio).to.be.true; + expect(resultBiblio).to.be.equal(resultArray); + expect(biblio.length).to.be.equal(array.length).to.be.equal(8); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/sort.js b/staff/ventura-rodriguez/biblio/sort.js new file mode 100644 index 00000000..9ce4baf2 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/sort.js @@ -0,0 +1,24 @@ +/** + * Sorts the elements of the Biblio instance in ascending order, optionally using a comparison function. + * + * @param {function?} callback - The comparison function to use for sorting. + * @returns {Biblio} The modified Biblio instance. + */ +function sort(callback) { + for (let i = 1; i < this.length; i++) { + const a = this[i - 1]; + const b = this[i]; + if ( + (!!callback && callback(a, b) > 0) || + (!callback && String(b) < String(a)) + ) { + const elementSaved = this[i - 1]; + this[i - 1] = this[i]; + this[i] = elementSaved; + i = 0; + } + } + return this; +} + +module.exports = sort; diff --git a/staff/ventura-rodriguez/biblio/sort.test.js b/staff/ventura-rodriguez/biblio/sort.test.js new file mode 100644 index 00000000..b63516ae --- /dev/null +++ b/staff/ventura-rodriguez/biblio/sort.test.js @@ -0,0 +1,26 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Sort method", () => { + it("Use sort without callback parameter", () => { + const array = [1, 30, 4, 21, 100000]; + const biblio = new Biblio(1, 30, 4, 21, 100000); + const resultArray = array.sort(); + const resultBiblio = biblio.sort(); + expect(resultBiblio).to.be.deep.equal(new Biblio(1, 100000, 21, 30, 4)); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(5); + }); + + it("Use sort using callback parameter", () => { + const array = [1, 30, 4, 21, 100000]; + const biblio = new Biblio(1, 30, 4, 21, 100000); + const resultArray = array.sort((a, b) => b - a); + const resultBiblio = biblio.sort((a, b) => b - a); + expect(resultBiblio).to.be.deep.equal(new Biblio(100000, 30, 21, 4, 1)); + for (let i = 0; i < resultArray.length; i++) + expect(resultBiblio[i]).to.be.equal(resultArray[i]); + expect(resultBiblio.length).to.be.equal(resultArray.length).to.be.equal(5); + }); +}); diff --git a/staff/ventura-rodriguez/biblio/splice.js b/staff/ventura-rodriguez/biblio/splice.js new file mode 100644 index 00000000..bf0d9c01 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/splice.js @@ -0,0 +1,32 @@ +const Biblio = require("./contructor"); + +function splice(_start, _deleteCount = 0) { + const initialLength = this.length; + const start = _start >= 0 ? _start : this.length + _start; + const deleteCount = + _deleteCount < this.length - start ? _deleteCount : this.length - start; + + const elementsToAdd = new Biblio(); + for (let i = 2; i < arguments.length; i++) { + elementsToAdd[elementsToAdd.length] = arguments[i]; + elementsToAdd.length += 1; + } + + const elementsToCopyAfter = new Biblio(); + for (let i = deleteCount; i < this.length - start; i++) { + elementsToCopyAfter[i] = this[start + i]; + elementsToCopyAfter.length += 1; + } + + for (let i = deleteCount; i < elementsToAdd.length; i++) + this[i + start] = elementsToAdd[i]; + + for (let i = deleteCount; i < elementsToCopyAfter.length; i++) + this[i + start + elementsToAdd.length] = elementsToCopyAfter[i]; + + if (deleteCount > 0) + this.length = initialLength - deleteCount - elementsToAdd.length; + else this.length = initialLength - deleteCount + elementsToAdd.length; +} + +module.exports = splice; diff --git a/staff/ventura-rodriguez/biblio/splice.test.js b/staff/ventura-rodriguez/biblio/splice.test.js new file mode 100644 index 00000000..2856c747 --- /dev/null +++ b/staff/ventura-rodriguez/biblio/splice.test.js @@ -0,0 +1,18 @@ +const { expect } = require("chai"); +const Biblio = require("."); + +describe("Splice method", () => { + it("Use splice passing al parameters with reasonable values", () => { + const biblio = new Biblio("Jan", "March", "April", "June"); + const array = ["Jan", "March", "April", "June"]; + biblio.splice(1, 0, "Feb"); + array.splice(1, 0, "Feb"); + debugger; + expect(biblio).to.be.deep.equal( + new Biblio("Jan", "Feb", "March", "April", "June") + ); + for (let i = 0; i < array.length; i++) + expect(biblio[i]).to.be.equal(array[i]); + expect(biblio.length).to.be.equal(array.length).to.be.equal(5); + }); +}); diff --git a/staff/ventura-rodriguez/chain-characters/at.js b/staff/ventura-rodriguez/chain-characters/at.js new file mode 100644 index 00000000..ed931eeb --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/at.js @@ -0,0 +1,28 @@ +const ChainCharacters = require("./contructor"); + +/** + * Retrieves the character at the specified index from the `value` array. + * + * If `index` is `null`, the function returns the first character of the `value` array. + * If `index` is positive, it returns the character at that position. + * If `index` is negative, it returns the character at that position counting from the end. + * + * @function at + * @param {number|null} index - The position of the character to retrieve. If `null`, returns the first character. + * @returns {string} - The character at the specified index. + */ +function at(index) { + if (index === null) return new ChainCharacters(this.value[0]); + + let result; + + for (let i = 0; i < this.length; i++) { + const character = this.value[i]; + + if (i === index) result = character; + else if (index < 0 && i === this.length + index) result = character; + } + return new ChainCharacters(result); +} + +module.exports = at; diff --git a/staff/ventura-rodriguez/chain-characters/at.test.js b/staff/ventura-rodriguez/chain-characters/at.test.js new file mode 100644 index 00000000..20961106 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/at.test.js @@ -0,0 +1,19 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("Hello").at(2); +console.assert(result1.value === "Hello".at(2), { + result: result1, + message: "Test 1 No pasado", +}); + +const result2 = new ChainCharacters("Hello").at(-1); +console.assert(result2.value === "Hello".at(-1), { + result: result2, + message: "Test 2 No pasado", +}); + +const result3 = new ChainCharacters("casoSinIndice").at(null); +console.assert(result3.value === "casoSinIndice".at(null), { + result: result3, + message: "Test 3 No pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/chart-at.js b/staff/ventura-rodriguez/chain-characters/chart-at.js new file mode 100644 index 00000000..042454c9 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/chart-at.js @@ -0,0 +1,26 @@ +const ChainCharacters = require("./contructor"); + +/** + * Retrieves the character at the specified index from the string-like object. + * + * If the `index` is not a number, the function returns the first character. + * If the `index` is out of bounds (greater than or equal to the length of the string), the function returns an empty string. + * + * @function charAt + * @param {number} index - The position of the character to retrieve. If not a number, returns the first character. + * @returns {string} - The character at the specified index, or the first character if `index` is not a number, + * or an empty string if `index` is out of bounds. + */ +function charAt(index) { + let result = this.value[index]; + + if (typeof index !== "number") { + result = this.value[0]; + } else if (index >= this.length) { + result = ""; + } + + return new ChainCharacters(result); +} + +module.exports = charAt; diff --git a/staff/ventura-rodriguez/chain-characters/chart-at.test.js b/staff/ventura-rodriguez/chain-characters/chart-at.test.js new file mode 100644 index 00000000..1ce5e518 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/chart-at.test.js @@ -0,0 +1,37 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("Hello").charAt(2); +console.assert(result1.value === "Hello".charAt(2), { + result: result1, + message: "Test 1 No pasado", +}); + +const result2 = new ChainCharacters("Hola").charAt(2); +console.assert(result2.value === "Hola".charAt(2), { + result: result2, + message: "Test 2 No pasado", +}); + +const result3 = new ChainCharacters("casoSinIndice").charAt(null); +console.assert(result3.value === "casoSinIndice".charAt(null), { + result: result3, + message: "Test 3 No pasado", +}); + +const result4 = new ChainCharacters("casoSinIndice").charAt(""); +console.assert(result4.value === "casoSinIndice".charAt(0), { + result: result4, + message: "Test 4 No pasado", +}); + +const result5 = new ChainCharacters("casoSinIndice").charAt(undefined); +console.assert(result5.value === "casoSinIndice".charAt(0), { + result: result5, + message: "Test 5 No pasado", +}); + +const result6 = new ChainCharacters("casoFueraDeRango").charAt(99); +console.assert(result6.value === "casoFueraDeRango".charAt(99), { + result: result6, + message: "Test 6 No pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/concat.js b/staff/ventura-rodriguez/chain-characters/concat.js new file mode 100644 index 00000000..760ffe96 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/concat.js @@ -0,0 +1,18 @@ +const ChainCharacters = require("./contructor"); + +/** + * Concatenates the current value with the provided arguments. + * + * @param {...string} args - The strings to concatenate. + * @returns {ChainCharacters} A new ChainCharacters instance with the concatenated value. + */ +function concat() { + let result = this.value; + for (let i = 0; i < arguments.length; i++) { + result += arguments[i]; + } + + return new ChainCharacters(result); +} + +module.exports = concat; diff --git a/staff/ventura-rodriguez/chain-characters/concat.test.js b/staff/ventura-rodriguez/chain-characters/concat.test.js new file mode 100644 index 00000000..f012bb2f --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/concat.test.js @@ -0,0 +1,19 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("a").concat("b"); +console.assert(result1.value === "a".concat("b"), { + result: result1, + message: "Test 1 no pasado", +}); + +const result2 = new ChainCharacters("a").concat("b", "c"); +console.assert(result2.value === "a".concat("b", "c"), { + result: result2, + message: "Test 2 no pasado", +}); + +const result3 = new ChainCharacters("a").concat("b", "c", "d", "e"); +console.assert(result3.value === "a".concat("b", "c", "d", "e"), { + result: result3, + message: "Test 3 no pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/contructor.js b/staff/ventura-rodriguez/chain-characters/contructor.js new file mode 100644 index 00000000..2f5ffb3f --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/contructor.js @@ -0,0 +1,20 @@ +/** + * Creates an instance of `ChainCharacter`, representing a string-like object with a `length` property. + * + * The `ChainCharacter` constructor calculates the length of the input string and assigns it + * to the `length` property of the instance. The original string is stored in the `value` property. + * + * @constructor + * @param {string} value - The string value to be stored in the `ChainCharacter` instance. + * @property {number} length - The length of the string `value`. + * @property {string} value - The original string passed to the constructor. + */ +function ChainCharacters(value) { + let _length = 0; + while (value[_length]) _length++; + + this.length = _length; + this.value = value; +} + +module.exports = ChainCharacters; diff --git a/staff/ventura-rodriguez/chain-characters/contructor.test.js b/staff/ventura-rodriguez/chain-characters/contructor.test.js new file mode 100644 index 00000000..a0e3fa55 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/contructor.test.js @@ -0,0 +1,13 @@ +const ChainCharacters = require("./contructor.js"); + +const result1 = new ChainCharacters("hello world"); +console.assert(result1.value === "hello world" && result1.length === 11, { + result: result1, + message: "Test 1 No pasado", +}); + +const result2 = new ChainCharacters("happy coding"); +console.assert(result2.value === "happy coding" && result2.length === 12, { + result: result2, + message: "Test 2 No pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/ends-with.js b/staff/ventura-rodriguez/chain-characters/ends-with.js new file mode 100644 index 00000000..608bc87f --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/ends-with.js @@ -0,0 +1,18 @@ +/** + * Checks if the current value ends with the specified substring. + * + * @param {string} searchString - The substring to search for. + * @param {number} [endPosition=this.length] - The position within the current value to start searching. + * @returns {boolean} True if the current value ends with the substring, false otherwise. + */ +function endsWith(searchString, endPosition = this.length) { + let subsString = ""; + + for (let i = 0; i < searchString.length; i++) { + subsString += this.value[endPosition - searchString.length + i]; + } + + return subsString === searchString; +} + +module.exports = endsWith; diff --git a/staff/ventura-rodriguez/chain-characters/ends-with.test.js b/staff/ventura-rodriguez/chain-characters/ends-with.test.js new file mode 100644 index 00000000..0f742911 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/ends-with.test.js @@ -0,0 +1,19 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("Cats are the best!").endsWith("best!"); +console.assert(result1 === "Cats are the best!".endsWith("best!"), { + result: result1, + message: "Test 1 no pasado", +}); + +const result2 = new ChainCharacters("Cats are the best!").endsWith("best", 17); +console.assert(result2 === "Cats are the best!".endsWith("best", 17), { + result: result2, + message: "Test 2 no pasado", +}); + +const result3 = new ChainCharacters("Cats are the best!").endsWith("best"); +console.assert(result3 === "Cats are the best!".endsWith("best"), { + result: result3, + message: "Test 3 no pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/includes.js b/staff/ventura-rodriguez/chain-characters/includes.js new file mode 100644 index 00000000..6e4151ab --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/includes.js @@ -0,0 +1,25 @@ +/** + * Checks if the current value includes the specified substring. + * + * @param {string} searchString - The substring to search for. + * @returns {boolean} True if the current value includes the substring, false otherwise. + */ +function includes(searchString) { + if (searchString === null) return false; + + let result = false; + + for (let i = 0; i < this.length; i++) { + let substring = ""; + + for (let j = 0; j < searchString.length; j++) { + substring += this.value[i + j]; + } + + if (substring === searchString) result = true; + } + + return result; +} + +module.exports = includes; diff --git a/staff/ventura-rodriguez/chain-characters/includes.test.js b/staff/ventura-rodriguez/chain-characters/includes.test.js new file mode 100644 index 00000000..6c602650 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/includes.test.js @@ -0,0 +1,43 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("Hello").includes("H"); +console.assert(result1 === "Hello".includes("H"), { + result: result1, + message: "Test 1 No pasado ", +}); + +const result2 = new ChainCharacters("Hola").includes("Ho"); +console.assert(result2 === "Hola".includes("Ho"), { + result: result2, + message: "Test 2 No pasado ", +}); + +const result3 = new ChainCharacters("casoSinIndice").includes(null); +console.assert(result3 === "casoSinIndice".includes(null), { + result: result3, + message: "Test 3 No pasado ", +}); + +const result4 = new ChainCharacters("world").includes("wr"); +console.assert(result4 === "world".includes("wr"), { + result: result4, + message: "Test 4 No pasado ", +}); + +const result5 = new ChainCharacters("world").includes("rld"); +console.assert(result5 === "world".includes("rld"), { + result: result5, + message: "Test 5 No pasado ", +}); + +const result6 = new ChainCharacters("world").includes("wod"); +console.assert(result6 === "world".includes("wod"), { + result: result6, + message: "Test 6 No pasado ", +}); + +const result7 = new ChainCharacters("world").includes("wu"); +console.assert(result7 === "world".includes("wu"), { + result: result7, + message: "Test 7 No pasado ", +}); diff --git a/staff/ventura-rodriguez/chain-characters/index-of.js b/staff/ventura-rodriguez/chain-characters/index-of.js new file mode 100644 index 00000000..ac54c24f --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/index-of.js @@ -0,0 +1,21 @@ +/** + * Finds the index of the first occurrence of the specified substring within the current value. + * + * @param {string} searchTerm - The substring to search for. + * @returns {number} The index of the first occurrence of the substring, or -1 if not found. + */ +function indexOf(searchTerm) { + for (let i = 0; i < this.length; i++) { + let subString = ""; + for (let j = 0; j < searchTerm.length; j++) { + subString += this.value[j + i]; + } + if (searchTerm === subString) { + return i; + } + } + + return -1; +} + +module.exports = indexOf; diff --git a/staff/ventura-rodriguez/chain-characters/index-of.test.js b/staff/ventura-rodriguez/chain-characters/index-of.test.js new file mode 100644 index 00000000..dc3fb276 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/index-of.test.js @@ -0,0 +1,29 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("This is a beautiful world").indexOf("w"); +console.assert(result1 === "This is a beautiful world".indexOf("w"), { + result: result1, + message: "Test 1 no pasado", +}); + +const result2 = new ChainCharacters("Maybe the world ends tomorrow").indexOf( + "o" +); +console.assert(result2 === "Maybe the world ends tomorrow".indexOf("o"), { + result: result2, + message: "Test 2 no pasado", +}); + +const result3 = new ChainCharacters("This is a beautiful world").indexOf( + "beautiful" +); +console.assert(result3 === "This is a beautiful world".indexOf("beautiful"), { + result: result3, + message: "Test 3 no pasado", +}); + +const result4 = new ChainCharacters("This is a beautiful world").indexOf("X"); +console.assert(result4 === "This is a beautiful world".indexOf("X"), { + result: result4, + message: "Test 4 no pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/index.js b/staff/ventura-rodriguez/chain-characters/index.js new file mode 100644 index 00000000..07cfd280 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/index.js @@ -0,0 +1,34 @@ +const ChainCharacters = require("./contructor.js"); +const at = require("./at.js"); +const charAt = require("./chart-at.js"); +const concat = require("./concat.js"); +const endsWith = require("./ends-with.js"); +const includes = require("./includes.js"); +const indexOf = require("./index-of.js"); +const repeat = require("./repeat.js"); +const replace = require("./replace.js"); +const slice = require("./slice.js"); +const split = require("./split.js"); +const startsWith = require("./starts-with.js"); +const substring = require("./substring.js"); +const toLowerCase = require("./to-lower-case.js"); +const toUpperCase = require("./to-upper-case.js"); +const trim = require("./trim.js"); + +ChainCharacters.prototype.at = at; +ChainCharacters.prototype.charAt = charAt; +ChainCharacters.prototype.concat = concat; +ChainCharacters.prototype.endsWith = endsWith; +ChainCharacters.prototype.includes = includes; +ChainCharacters.prototype.indexOf = indexOf; +ChainCharacters.prototype.repeat = repeat; +ChainCharacters.prototype.replace = replace; +ChainCharacters.prototype.slice = slice; +ChainCharacters.prototype.split = split; +ChainCharacters.prototype.startsWith = startsWith; +ChainCharacters.prototype.substring = substring; +ChainCharacters.prototype.toLowerCase = toLowerCase; +ChainCharacters.prototype.toUpperCase = toUpperCase; +ChainCharacters.prototype.trim = trim; + +module.exports = ChainCharacters; diff --git a/staff/ventura-rodriguez/chain-characters/index.test.js b/staff/ventura-rodriguez/chain-characters/index.test.js new file mode 100644 index 00000000..180ba053 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/index.test.js @@ -0,0 +1,16 @@ +require("./contructor.test.js"); +require("./at.test.js"); +require("./chart-at.test.js"); +require("./concat.test.js"); +require("./ends-with.test.js"); +require("./includes.test.js"); +require("./index-of.test.js"); +require("./repeat.test.js"); +require("./replace.test.js"); +require("./slice.test.js"); +require("./split.test.js"); +require("./starts-with.test.js"); +require("./substring.test.js"); +require("./to-lower-case.test.js"); +require("./to-upper-case.test.js"); +require("./trim.test.js"); diff --git a/staff/ventura-rodriguez/chain-characters/repeat.js b/staff/ventura-rodriguez/chain-characters/repeat.js new file mode 100644 index 00000000..651a42ab --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/repeat.js @@ -0,0 +1,19 @@ +const ChainCharacters = require("./contructor"); + +/** + * Repeats the current value a specified number of times. + * + * @param {number} count - The number of times to repeat the value. + * @returns {ChainCharacters} A new ChainCharacters instance with the repeated value. + */ +function repeat(count) { + let result = ""; + + for (let i = 0; i < count; i++) { + result += this.value; + } + + return new ChainCharacters(result); +} + +module.exports = repeat; diff --git a/staff/ventura-rodriguez/chain-characters/repeat.test.js b/staff/ventura-rodriguez/chain-characters/repeat.test.js new file mode 100644 index 00000000..34a86218 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/repeat.test.js @@ -0,0 +1,13 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("a").repeat(3); +console.assert(result1.value === "a".repeat(3), { + result: result1, + message: "Test 1 No pasado", +}); + +const result2 = new ChainCharacters("Hello").repeat(5); +console.assert(result2.value === "Hello".repeat(5), { + result: result2, + message: "Test 2 No pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/replace.js b/staff/ventura-rodriguez/chain-characters/replace.js new file mode 100644 index 00000000..7c530c4f --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/replace.js @@ -0,0 +1,33 @@ +const ChainCharacters = require("./contructor"); + +/** + * Replaces all occurrences of a specified substring with another string. + * + * @param {string} strSearch - The substring to search for. + * @param {string} strRepWith - The string to replace the substring with. + * @returns {ChainCharacters} A new ChainCharacters instance with the replaced occurrences. + */ +function replace(strSearch, strRepWith) { + let strFinal = ""; + let valorEncontrado = false; + + for (let i = 0; i < this.length; i++) { + let match = true; + for (let j = 0; j < strSearch.length; j++) { + if (this.value[i + j] !== strSearch[j]) { + match = false; + break; + } + } + if (!valorEncontrado && match) { + strFinal += strRepWith; + i += strSearch.length - 1; + valorEncontrado = true; + } else { + strFinal += this.value[i]; + } + } + return new ChainCharacters(strFinal); +} + +module.exports = replace; diff --git a/staff/ventura-rodriguez/chain-characters/replace.test.js b/staff/ventura-rodriguez/chain-characters/replace.test.js new file mode 100644 index 00000000..f870af62 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/replace.test.js @@ -0,0 +1,26 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("Hola, mundo!").replace( + "mundo", + "hijos del soul" +); +console.assert(result1.value === "Hola, hijos del soul!", { + result: result1, + message: "Test 1 No pasado", +}); + +const result2 = new ChainCharacters( + "Change My Mind: Pineapple Belongs on Pizza" +).replace("Change My Mind", "Convince Me"); +console.assert(result2.value === "Convince Me: Pineapple Belongs on Pizza", { + result: result2, + message: "Test 2 not passed", +}); + +const result3 = new ChainCharacters( + "Why You Always Lying? Stop Lying!" +).replace("Why You Always Lying", "Stop Lying"); +console.assert(result3.value === "Stop Lying? Stop Lying!", { + result: result3, + message: "Test 3 not passed", +}); diff --git a/staff/ventura-rodriguez/chain-characters/slice.js b/staff/ventura-rodriguez/chain-characters/slice.js new file mode 100644 index 00000000..dfe6c4b6 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/slice.js @@ -0,0 +1,19 @@ +const ChainCharacters = require("./contructor"); + +/** + * Extracts a substring from the current value starting at the specified index. + * + * @param {number} start - The index to start extracting from. + * @returns {ChainCharacters} A new ChainCharacters instance with the extracted substring. + */ +function slice(start) { + let result = ""; + + for (let i = start; i < this.length; i++) { + result += this.value[i]; + } + + return new ChainCharacters(result); +} + +module.exports = slice; diff --git a/staff/ventura-rodriguez/chain-characters/slice.test.js b/staff/ventura-rodriguez/chain-characters/slice.test.js new file mode 100644 index 00000000..86dbed56 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/slice.test.js @@ -0,0 +1,13 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("Hola mundo").slice(4); +console.assert(result1.value === "Hola mundo".slice(4), { + result: result1, + message: "Test 1 no pasado", +}); + +const result2 = new ChainCharacters("que tal como estas").slice(10); +console.assert(result2.value === "que tal como estas".slice(10), { + result: result2, + message: "Test 2 no pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/split.js b/staff/ventura-rodriguez/chain-characters/split.js new file mode 100644 index 00000000..20b63da9 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/split.js @@ -0,0 +1,34 @@ +/** + * Splits the current value into an array of substrings based on the specified separator and limit. + * + * @param {string} separator - The separator to split on. + * @param {number} [limit=Infinity] - The maximum number of elements to return. + * @returns {string[]} An array of substrings. + */ +function split(separator = 0, limit = Infinity) { + const result = []; + let currentSegment = ""; + + for (let i = 0; i < this.length && result.length <= limit - 1; i++) { + let subString = ""; + + for (let j = 0; j < separator.length; j++) { + subString = this.value[i + j]; + } + + if (subString === separator) { + i = i + separator.length - 1; + result[result.length] = currentSegment; + currentSegment = ""; + } else { + currentSegment += this.value[i]; + } + } + + if (currentSegment !== "" && result.length <= limit - 1) + result[result.length] = currentSegment; + + return result; +} + +module.exports = split; diff --git a/staff/ventura-rodriguez/chain-characters/split.test.js b/staff/ventura-rodriguez/chain-characters/split.test.js new file mode 100644 index 00000000..01cee7de --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/split.test.js @@ -0,0 +1,64 @@ +const ChainCharacters = require("."); + +function arrayIsEqual(arr1, arr2) { + if (arr1.length !== arr2.length) return false; + let result = true; + let i = 0; + while (i < arr1.length || result === false) { + if (arr1[i] !== arr2[i]) { + result = false; + } + i++; + } + return result; +} + +debugger; +const result1 = new ChainCharacters("Angela,26 años").split(","); +console.assert(arrayIsEqual(result1, ["Angela", "26 años"]), { + result: result1, + message: "Test 1 No pasado", +}); + +debugger; +const result2 = new ChainCharacters("Monday,Tuesday,Wednesday,Thursday").split( + "," +); +console.assert( + arrayIsEqual(result2, ["Monday", "Tuesday", "Wednesday", "Thursday"]), + { + result: result2, + message: "Test 2 No pasado", + } +); + +debugger; +const result3 = new ChainCharacters("Monday,Tuesday,Wednesday,Thursday").split( + ",", + 2 +); +console.assert(arrayIsEqual(result3, ["Monday", "Tuesday"]), { + result: result3, + message: "Test 3 No pasado", +}); + +debugger; +const result4 = new ChainCharacters("1 2 3 4 5 6").split(" ", 3); +console.assert(arrayIsEqual(result4, ["1", "2", "3"]), { + result: result4, + message: "Test 4 No pasado", +}); + +debugger; +const result5 = new ChainCharacters("2024-07-20").split("-", 3); +console.assert(arrayIsEqual(result5, ["2024", "07", "20"]), { + result: result5, + message: "Test 5 No pasado", +}); + +debugger; +const result6 = new ChainCharacters("2024-07-20").split(" ", 3); +console.assert(result6[0] === "2024-07-20", { + result: result6, + message: "Test 6 No pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/starts-with.js b/staff/ventura-rodriguez/chain-characters/starts-with.js new file mode 100644 index 00000000..de0a44f8 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/starts-with.js @@ -0,0 +1,17 @@ +/** + * Checks if the current value starts with the specified substring. + * + * @param {string} searchString - The substring to search for. + * @returns {boolean} True if the current value starts with the substring, false otherwise. + */ +function startsWith(searchString) { + let result = true; + for (let i = 0; i < searchString.length; i++) { + if (this.value[i] !== searchString[i]) { + result = false; + } + } + return result; +} + +module.exports = startsWith; diff --git a/staff/ventura-rodriguez/chain-characters/starts-with.test.js b/staff/ventura-rodriguez/chain-characters/starts-with.test.js new file mode 100644 index 00000000..ef1d2562 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/starts-with.test.js @@ -0,0 +1,19 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("Hola mundo").startsWith("Hola"); +console.assert(result1 === "Hola mundo".startsWith("Hola"), { + result: result1, + message: "Test 1 no pasado", +}); + +const result2 = new ChainCharacters("Test the function").startsWith("Test"); +console.assert(result2 === "Test the function".startsWith("Test"), { + result: result2, + message: "Test 2 no pasado", +}); + +const result3 = new ChainCharacters("Test the function").startsWith("Hola"); +console.assert(result3 === "Test the function".startsWith("Hola"), { + result: result3, + message: "Test 3 no pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/substring.js b/staff/ventura-rodriguez/chain-characters/substring.js new file mode 100644 index 00000000..7bd3a096 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/substring.js @@ -0,0 +1,17 @@ +const ChainCharacters = require("./contructor"); + +/** + * Extracts a substring from the current value starting at the specified index. + * + * @param {number} indexStart - The index to start extracting from. + * @returns {ChainCharacters} A new ChainCharacters instance with the extracted substring. + */ +function substring(indexStart) { + let result = ""; + for (let i = indexStart; i < this.length; i++) { + result += this.value[i]; + } + return new ChainCharacters(result); +} + +module.exports = substring; diff --git a/staff/ventura-rodriguez/chain-characters/substring.test.js b/staff/ventura-rodriguez/chain-characters/substring.test.js new file mode 100644 index 00000000..c87436f9 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/substring.test.js @@ -0,0 +1,17 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters("que tal como estas").substring(5); +console.assert(result1.value === "que tal como estas".substring(5), { + result: result1, + message: "Test 1 no pasado", +}); + +const result2 = new ChainCharacters("lalala").substring(3); +console.assert( + result2.value === "lalala".substring(3), + + { + result: result2, + message: "Test 2 no pasado", + } +); diff --git a/staff/ventura-rodriguez/chain-characters/to-lower-case.js b/staff/ventura-rodriguez/chain-characters/to-lower-case.js new file mode 100644 index 00000000..ccb7fe54 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/to-lower-case.js @@ -0,0 +1,56 @@ +const ChainCharacters = require("./contructor"); + +/** + * Converts the current value to lowercase. + * + * @returns {ChainCharacters} A new ChainCharacters instance with the converted value. + */ +function toLowerCase() { + let result = ""; + const converter = [ + ["A", "a"], + ["B", "b"], + ["C", "c"], + ["D", "d"], + ["E", "e"], + ["F", "f"], + ["G", "g"], + ["H", "h"], + ["I", "i"], + ["J", "j"], + ["K", "k"], + ["L", "l"], + ["M", "m"], + ["N", "n"], + ["O", "o"], + ["P", "p"], + ["Q", "q"], + ["R", "r"], + ["S", "s"], + ["T", "t"], + ["U", "u"], + ["V", "v"], + ["W", "w"], + ["X", "x"], + ["Y", "y"], + ["Z", "z"], + ]; + + for (let i = 0; i < this.length; i++) { + const character = this.value[i]; + + for (let j = 0; j < converter.length; j++) { + const value = converter[j]; + if (character === value[0]) { + result += value[1]; + } + } + if (result.length !== i + 1) { + result += character; + } + } + + return new ChainCharacters(result); +} + +module.exports = toLowerCase; diff --git a/staff/ventura-rodriguez/chain-characters/to-lower-case.test.js b/staff/ventura-rodriguez/chain-characters/to-lower-case.test.js new file mode 100644 index 00000000..b4db69a2 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/to-lower-case.test.js @@ -0,0 +1,24 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters( + "¡Me siento bieN, porque eL sofá Es Nuevo!" +).toLowerCase(); +console.assert( + result1.value === "¡Me siento bieN, porque eL sofá Es Nuevo!".toLowerCase(), + { + result: result1, + message: "Test 1 no pasado", + } +); + +const result2 = new ChainCharacters("12344ABCDeee").toLowerCase(); +console.assert(result2.value === "12344ABCDeee".toLowerCase(), { + result: result2, + message: "Test 2 no pasado", +}); + +const result3 = new ChainCharacters("null vaLue").toLowerCase(); +console.assert(result3.value === "null vaLue".toLowerCase(), { + result: result3, + message: "Test 3 no pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/to-upper-case.js b/staff/ventura-rodriguez/chain-characters/to-upper-case.js new file mode 100644 index 00000000..cf66f1ed --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/to-upper-case.js @@ -0,0 +1,57 @@ +const ChainCharacters = require("./contructor"); + +/** + * Converts the current value to uppercase. + * + * @returns {ChainCharacters} A new ChainCharacters instance with the converted value. + */ +function toUpperCase() { + let result = ""; + const converter = [ + ["a", "A"], + ["á", "Á"], + ["b", "B"], + ["c", "C"], + ["d", "D"], + ["e", "E"], + ["f", "F"], + ["g", "G"], + ["h", "H"], + ["i", "I"], + ["j", "J"], + ["k", "K"], + ["l", "L"], + ["m", "M"], + ["n", "N"], + ["o", "O"], + ["p", "P"], + ["q", "Q"], + ["r", "R"], + ["s", "S"], + ["t", "T"], + ["u", "U"], + ["v", "V"], + ["w", "W"], + ["x", "X"], + ["y", "Y"], + ["z", "Z"], + ]; + + for (let i = 0; i < this.length; i++) { + const character = this.value[i]; + + for (let j = 0; j < converter.length; j++) { + const value = converter[j]; + if (character === value[0]) { + result += value[1]; + } + } + if (result.length !== i + 1) { + result += character; + } + } + + return new ChainCharacters(result); +} + +module.exports = toUpperCase; diff --git a/staff/ventura-rodriguez/chain-characters/to-upper-case.test.js b/staff/ventura-rodriguez/chain-characters/to-upper-case.test.js new file mode 100644 index 00000000..1a9bf7c4 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/to-upper-case.test.js @@ -0,0 +1,24 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters( + "¡Me siento bieN, porque eL sofá Es Nuevo!" +).toUpperCase(); +console.assert( + result1.value === "¡Me siento bieN, porque eL sofá Es Nuevo!".toUpperCase(), + { + result: result1, + message: "Test 1 no pasado", + } +); + +const result2 = new ChainCharacters("12344ABCDeee").toUpperCase(); +console.assert(result2.value === "12344ABCDeee".toUpperCase(), { + result: result2, + message: "Test 2 no pasado", +}); + +const result3 = new ChainCharacters("null vaLue").toUpperCase(); +console.assert(result3.value === "null vaLue".toUpperCase(), { + result: result3, + message: "Test 3 no pasado", +}); diff --git a/staff/ventura-rodriguez/chain-characters/trim.js b/staff/ventura-rodriguez/chain-characters/trim.js new file mode 100644 index 00000000..1f86196d --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/trim.js @@ -0,0 +1,21 @@ +const ChainCharacters = require("./contructor"); + +/** + * Removes leading and trailing whitespace from the current value. + * + * @returns {ChainCharacters} A new ChainCharacters instance with the trimmed value. + */ +function trim() { + let result = ""; + let firstPosition = 0; + let lastPosition = this.length - 1; + + while (this.value[firstPosition] === " ") firstPosition++; + while (this.value[lastPosition] === " ") lastPosition--; + + for (let i = firstPosition; i <= lastPosition; i++) result += this.value[i]; + + return new ChainCharacters(result); +} + +module.exports = trim; diff --git a/staff/ventura-rodriguez/chain-characters/trim.test.js b/staff/ventura-rodriguez/chain-characters/trim.test.js new file mode 100644 index 00000000..43f738e8 --- /dev/null +++ b/staff/ventura-rodriguez/chain-characters/trim.test.js @@ -0,0 +1,19 @@ +const ChainCharacters = require("."); + +const result1 = new ChainCharacters(" belen ").trim(); +console.assert(result1.value === " belen ".trim(), { + result: result1, + message: "Test 1 no pasado", +}); + +const result2 = new ChainCharacters(" no se").trim(); +console.assert(result2.value === " no se".trim(), { + result: result2, + message: "Test 2 no pasado", +}); + +const result3 = new ChainCharacters("Hola como estás?").trim(); +console.assert(result3.value === "Hola como estás?".trim(), { + result: result3, + message: "Test 3 no pasado", +}); diff --git a/staff/ventura-rodriguez/string-standalone/concat.js b/staff/ventura-rodriguez/string-standalone/concat.js index 130279fe..e5f9015b 100644 --- a/staff/ventura-rodriguez/string-standalone/concat.js +++ b/staff/ventura-rodriguez/string-standalone/concat.js @@ -1,9 +1,5 @@ function concat() { let result = ""; -<<<<<<< Updated upstream - -======= ->>>>>>> Stashed changes for (let i = 0; i < arguments.length; i++) { result += arguments[i]; } @@ -12,24 +8,12 @@ function concat() { } { -<<<<<<< Updated upstream - const result1 = concat("que", "tal"); - console.assert(result1 === "quetal".concat(), { -======= const result1 = concat("a", "b"); console.assert(result1 === "a".concat("b"), { ->>>>>>> Stashed changes result: result1, message: "Test 1 no pasado", }); -<<<<<<< Updated upstream - const result2 = concat(1, 2, 3); - console.assert(result2 === "123".concat(), { - result: result2, - message: "Test 2 no pasado", - }); -======= const result2 = concat("a", "b", "c"); console.assert(result2 === "a".concat("b", "c"), { result: result2, @@ -41,5 +25,4 @@ function concat() { result: result3, message: "Test 3 no pasado", }); ->>>>>>> Stashed changes } diff --git a/staff/ventura-rodriguez/string-standalone/includes.js b/staff/ventura-rodriguez/string-standalone/includes.js index c65e0f7c..d5538128 100644 --- a/staff/ventura-rodriguez/string-standalone/includes.js +++ b/staff/ventura-rodriguez/string-standalone/includes.js @@ -19,41 +19,41 @@ function includes(string, searchString) { const result1 = includes("Hello", "H"); console.assert(result1 === "Hello".includes("H"), { result: result1, - message: "Test 1 No pasado ", + message: "Test 1 No pasado", }); const result2 = includes("Hola", "Ho"); console.assert(result2 === "Hola".includes("Ho"), { result: result2, - message: "Test 2 No pasado ", + message: "Test 2 No pasado", }); const result3 = includes("casoSinIndice", null); console.assert(result3 === "casoSinIndice".includes(null), { result: result3, - message: "Test 3 No pasado ", + message: "Test 3 No pasado", }); const result4 = includes("world", "wr"); console.assert(result4 === "world".includes("wr"), { result: result4, - message: "Test 4 No pasado ", + message: "Test 4 No pasado", }); const result5 = includes("world", "rld"); console.assert(result5 === "world".includes("rld"), { result: result5, - message: "Test 5 No pasado ", + message: "Test 5 No pasado", }); const result6 = includes("world", "wod"); console.assert(result6 === "world".includes("wod"), { result: result6, - message: "Test 6 No pasado ", + message: "Test 6 No pasado", }); const result7 = includes("world", "wu"); console.assert(result7 === "world".includes("wu"), { result: result7, - message: "Test 7 No pasado ", + message: "Test 7 No pasado", }); diff --git a/staff/ventura-rodriguez/string-standalone/repeat.js b/staff/ventura-rodriguez/string-standalone/repeat.js index a7d4bc88..0026c20c 100644 --- a/staff/ventura-rodriguez/string-standalone/repeat.js +++ b/staff/ventura-rodriguez/string-standalone/repeat.js @@ -8,44 +8,16 @@ function repeat(string, count) { return result; } -const result1 = includes("Hello", "H"); -console.assert(result1 === "Hello".includes("H"), { - result: result1, - message: "Test 1 No pasado ", -}); - -const result2 = includes("Hola", "Ho"); -console.assert(result2 === "Hola".includes("Ho"), { - result: result2, - message: "Test 2 No pasado ", -}); - -const result3 = includes("casoSinIndice", null); -console.assert(result3 === "casoSinIndice".includes(null), { - result: result3, - message: "Test 3 No pasado ", -}); - -const result4 = includes("world", "wr"); -console.assert(result4 === "world".includes("wr"), { - result: result4, - message: "Test 4 No pasado ", -}); - -const result5 = includes("world", "rld"); -console.assert(result5 === "world".includes("rld"), { - result: result5, - message: "Test 5 No pasado ", -}); - -const result6 = includes("world", "wod"); -console.assert(result6 === "world".includes("wod"), { - result: result6, - message: "Test 6 No pasado ", -}); - -const result7 = includes("world", "wu"); -console.assert(result7 === "world".includes("wu"), { - result: result7, - message: "Test 7 No pasado ", -}); +{ + const result1 = repeat("a", 3); + console.assert(result1 === "a".repeat(3), { + result: result1, + message: "Test 1 No pasado", + }); + + const result2 = repeat("Hello", 5); + console.assert(result2 === "Hello".repeat(5), { + result: result2, + message: "Test 2 No pasado", + }); +} diff --git a/staff/ventura-rodriguez/string-standalone/replace.js b/staff/ventura-rodriguez/string-standalone/replace.js index 7ec9bba5..8ed35db8 100644 --- a/staff/ventura-rodriguez/string-standalone/replace.js +++ b/staff/ventura-rodriguez/string-standalone/replace.js @@ -21,28 +21,30 @@ function replace(string, strSearch, strRepWith) { return strFinal; } -const result1 = replace("Hola, mundo!", "mundo", "hijos del soul"); -console.assert(result1 === "Hola, hijos del soul!", { - result: result1, - message: "Test 1 No pasado", -}); +{ + const result1 = replace("Hola, mundo!", "mundo", "hijos del soul"); + console.assert(result1 === "Hola, hijos del soul!", { + result: result1, + message: "Test 1 No pasado", + }); -const result2 = replace( - "Change My Mind: Pineapple Belongs on Pizza", - "Change My Mind", - "Convince Me" -); -console.assert(result2 === "Convince Me: Pineapple Belongs on Pizza", { - result: result2, - message: "Test 2 not passed", -}); + const result2 = replace( + "Change My Mind: Pineapple Belongs on Pizza", + "Change My Mind", + "Convince Me" + ); + console.assert(result2 === "Convince Me: Pineapple Belongs on Pizza", { + result: result2, + message: "Test 2 not passed", + }); -const result3 = replace( - "Why You Always Lying? Stop Lying!", - "Why You Always Lying", - "Stop Lying" -); -console.assert(result3 === "Stop Lying? Stop Lying!", { - result: result3, - message: "Test 3 not passed", -}); + const result3 = replace( + "Why You Always Lying? Stop Lying!", + "Why You Always Lying", + "Stop Lying" + ); + console.assert(result3 === "Stop Lying? Stop Lying!", { + result: result3, + message: "Test 3 not passed", + }); +}