Skip to content

Commit

Permalink
add prototypes b00tc4mp#185
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos committed Sep 12, 2024
1 parent ea22ad0 commit abd2b07
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 41 deletions.
5 changes: 4 additions & 1 deletion staff/carlos-bock/chain-characters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const concat = require("./concat.js")
const endsWith = require("./endsWith.js")
const includes = require("./includes.js")
const indexOf = require("./indexOf.js")
const replace = require("./replace.js")
const repeat = require("./repeat.js")

const slice = require("./slice.js")

const split = require("./split.js")

Expand All @@ -22,7 +23,9 @@ ChainCharacters.prototype.concat = concat;
ChainCharacters.prototype.endsWith = endsWith;
ChainCharacters.prototype.includes = includes;
ChainCharacters.prototype.indexOf = indexOf;
ChainCharacters.prototype.replace = replace;
ChainCharacters.prototype.repeat = repeat;
ChainCharacters.prototype.slice = slice;


ChainCharacters.prototype.split = split;
Expand Down
3 changes: 2 additions & 1 deletion staff/carlos-bock/chain-characters/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ require("./concat.test.js");
require("./endsWith.test.js");
require("./includes.test.js");
require("./indexOf.test.js");
require("./replace.test.js");
require("./repeat.test.js");

require("./slice.test.js");

require("./split.test.js");

Expand Down
31 changes: 7 additions & 24 deletions staff/carlos-bock/chain-characters/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
//si parametro === a string[i] entonces newString = string[string.length-index] + parametro + string[segunda mitad]
//resolver primero string al principio

const ChainCharacters = require("./constructor");

function replace(string, oldPhrase, newPhrase) {
const oldString = string;
function replace(oldPhrase, newPhrase) { //removed string parameter
const oldString = this.value;
let result = false;
let newString ="";

Expand All @@ -19,7 +20,7 @@ function replace(string, oldPhrase, newPhrase) {
let solution = true;

for (let j = 0; j < oldPhrase.length; j++) {
if (string[i + j] !== oldPhrase[j]){
if (this.value[i + j] !== oldPhrase[j]){
solution = false;
break;
}
Expand All @@ -31,29 +32,11 @@ function replace(string, oldPhrase, newPhrase) {
i += oldPhrase.length - 1;
result = true;
} else {
newString += string[i];
newString += this.value[i];
}
}

return newString;
return new ChainCharacters(newString);
}

const aString = "My favorite color is blue";
const oldWord = "blue";
const newWord = "red";

const stringB = "Cual es el mejor bootcamp";
const pregunta = "Cual";
const respuesta = "ISDI";

const result1 = replace(aString, oldWord, newWord);
console.assert(result1 === aString.replace(oldWord, newWord),{
result: result1,
message: "Test 1 No pasado ",
});

const result2 = replace(stringB, pregunta, respuesta);
console.assert(result2 === stringB.replace(pregunta, respuesta),{
result: result2,
message: "Test 1 No pasado ",
});
module.exports = replace;
23 changes: 23 additions & 0 deletions staff/carlos-bock/chain-characters/replace.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


const ChainCharacters = require("./");

const aString = "My favorite color is blue";
const oldWord = "blue";
const newWord = "red";

const stringB = "Cual es el mejor bootcamp";
const pregunta = "Cual";
const respuesta = "ISDI";

const result1 = new ChainCharacters(aString).replace(oldWord, newWord);
console.assert(result1.value === aString.replace(oldWord, newWord),{
result: result1,
message: "Test 1 No pasado ",
});

const result2 = new ChainCharacters(stringB).replace(pregunta, respuesta);
console.assert(result2.value === stringB.replace(pregunta, respuesta),{
result: result2,
message: "Test 1 No pasado ",
});
21 changes: 6 additions & 15 deletions staff/carlos-bock/chain-characters/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
//si hay dos parametros usa el primer indice hasta llegar al segundo para crear el nuevo string
//si los indices sone negativos se cuentan desde el final del string original.

function slice(string, index1, index2) {
const ChainCharacters = require("./constructor");

function slice(index1, index2) {
let newString = "";

for (let i = index1; i < index2; i++) {
newString += string[i];
newString += this.value[i];
}
return newString;
return new ChainCharacters(newString);
}



const string1 = "Madrid es la mejor ciudad del mundo."
const indexOne = 6;
const indexTwo = 12;


const result1 = slice(string1, 1, 3 );
console.assert(result1 === string1.slice(1, 3),{
result: result1,
message: "Test 1 No pasado ",
});
module.exports = slice
11 changes: 11 additions & 0 deletions staff/carlos-bock/chain-characters/slice.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


const ChainCharacters = require("./");

const string1 = "Madrid es la mejor ciudad del mundo."

const result1 = new ChainCharacters(string1).slice(1, 3 );
console.assert(result1.value === string1.slice(1, 3),{
result: result1,
message: "Test 1 No pasado ",
});

0 comments on commit abd2b07

Please sign in to comment.