Skip to content

Commit

Permalink
add completed prototypes b00tc4mp#185
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos committed Sep 2, 2024
1 parent 9eca66b commit 646ff49
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 120 deletions.
4 changes: 2 additions & 2 deletions staff/carlos-bock/chain-characters/constructor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function ChainCharacter(value) {
function ChainCharacters(value) {
let _length = 0;
while(value[_length]) _length++;

this.length = _length;
this.value = value;
}

module.exports = ChainCharacter;
module.exports = ChainCharacters;
14 changes: 14 additions & 0 deletions staff/carlos-bock/chain-characters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ const at = require("./at.js");
const charAt = require("./charAt.js");
const concat = require("./concat.js")

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

const toLowerCase = require("./toLowerCase.js")
const toUpperCase = require("./toUpperCase.js")
const trim = require("./trim.js")


ChainCharacters.prototype.at = at;
ChainCharacters.prototype.charAt = charAt;
ChainCharacters.prototype.concat = concat;

ChainCharacters.prototype.split = split;

ChainCharacters.prototype.toLowerCase = toLowerCase;
ChainCharacters.prototype.toUpperCase = toUpperCase;
ChainCharacters.prototype.trim = trim;


module.exports = ChainCharacters;
9 changes: 8 additions & 1 deletion staff/carlos-bock/chain-characters/index.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
require("./at.test.js");
require("./charAt.test.js");
require("./concat.test.js");
require("./concat.test.js");


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

require("./toLowerCase.test.js");
require("./toUpperCase.test.js");
require("./trim.test.js");
73 changes: 16 additions & 57 deletions staff/carlos-bock/chain-characters/split.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

// posiblemente pegar el código original
//si es numero o null meter toda la frase en un array
//split
// se resive un string y un patron
Expand All @@ -10,78 +10,37 @@
// "hola que tal" --> split("l")["ho", " a que tap"]
// "hola" --> hola.length = 4 ; hola[hola.length - 1] = "a"

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

function split(string, pattern) {
function split(pattern) {
const newArray = [];
let tempString = "";
let tempString = new ChainCharacters("");


for (let i = 0; i < string.length; i++) {
for (let i = 0; i < this.length; i++) {

if (pattern === ""){
newArray[i] = string[i]; //para separar por caracteres
tempString = "";
newArray[i] = this.value[i] //para separar por caracteres
tempString.value = "";
}

else if (i === string.length -1 && string[string.length-1] !== pattern ){
tempString += string[i];
newArray[newArray.length] = tempString;
else if (i === this.length -1 && this.value[this.length-1] !== pattern ){
tempString.value += this.value[i];
newArray[newArray.length] = tempString.value;
}

else if (pattern === string[i] || i === string.length -1 ){
newArray[newArray.length] = tempString;
tempString = "";
else if (pattern === this.value[i] || i === this.length -1 ){
newArray[newArray.length] = tempString.value;
tempString.value = "";
}

else {
tempString += string[i];
tempString += this.value[i];
//si no toca dividir, ir construyendo tempString
}
}

return newArray;
}

function compare(array1, array2) {
let result = true;
let i = 0;
if (array1.length !== array2.length) return false;
while (i < array1.length) {
if (array1[i] !== array2[i]) {
result = false;
}
i++;
}
return result;
}

const str = 'Esta es una oración que tiene que estar split.';
const pattern = "";
const pattern2 = " ";
const pattern3 = "q";
const pattern4 = "e";

const result1 = split(str, pattern);
const result2 = split(str, pattern2);
const result3 = split(str, pattern3);
const result4 = split(str, pattern4);

console.assert(compare(result1, str.split(pattern)),{
result: result1,
message: "Test 1 No pasado ",
});


console.assert(compare(result2, str.split(pattern2)),{
result: result2,
message: "Test 2 No pasado ",
});

console.assert(compare(result3, str.split(pattern3)),{
result: result3,
message: "Test 3 No pasado ",
});

console.assert(compare(result4, str.split(pattern4)),{
result: result4,
message: "Test 3 No pasado ",
});
module.exports = split;
51 changes: 51 additions & 0 deletions staff/carlos-bock/chain-characters/split.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

const ChainCharacters = require("./");

function compare(array1, array2) {
let result = true;
let i = 0;
if (array1.length !== array2.length) return false;
while (i < array1.length) {
if (array1[i].value !== array2[i]) {
result = false;
}
i++;
}
return result;
}


//const str = 'Esta es una oración que tiene que estar split.';
const pattern = "";
const pattern2 = " ";
const pattern3 = "q";
const pattern4 = "e";

//const result1 = split(str, pattern);
//const result2 = split(str, pattern2);
//const result3 = split(str, pattern3);
//const result4 = split(str, pattern4);


const result1 = new ChainCharacters('Esta es una oración que tiene que estar split.').split(pattern);
console.assert(compare(result1, 'Esta es una oración que tiene que estar split.'.split(pattern)),{
result: result1,
message: "Test 1 No pasado ",
});

/*
console.assert(compare(result2, str.split(pattern2)),{
result: result2,
message: "Test 2 No pasado ",
});
console.assert(compare(result3, str.split(pattern3)),{
result: result3,
message: "Test 3 No pasado ",
});
console.assert(compare(result4, str.split(pattern4)),{
result: result4,
message: "Test 3 No pasado ",
});
*/
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,25 @@
//Tenemos que correr y asignar valores si el valor de oldString[i] es igual a valor de upperCase[]
// string[i]

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

function toLowerCase(string) {
const lowerCase = "aábcdeéfghiíjklmnñoópqrstuúvwxyz ";
const upperCase = "AÁBCDEÉFGHIÍJKLMNÑOÓPQRSTUÚVWXYZ ";
let newString = "";

for (let i = 0; i < string.length; i++) {
for (let i = 0; i < this.length; i++) {
for (let j = 0; j < upperCase.length; j++) {
if (string[i] === lowerCase[j]) {
if (this.value[i] === lowerCase[j]) {
newString +=lowerCase[j];
}
else if(string[i] === upperCase[j]) {
else if(this.value[i] === upperCase[j]) {
newString += lowerCase[j];
}
}

}
return newString;
return new ChainCharacters(newString);
}

const oldString = "THIS IS A STRING WITH UPPERCASE";
const oldString2 = "This Is a Test";


const result1 = toLowerCase(oldString);
console.assert(result1 === oldString.toLowerCase(),{
result: result1,
message: "Test 1 No pasado ",
});

const result2 = toLowerCase(oldString2);
console.assert(result2 === oldString2.toLowerCase(), {
result: result2,
message: "Test 2 No pasado ",
});


module.exports = toLowerCase;
20 changes: 20 additions & 0 deletions staff/carlos-bock/chain-characters/toLowerCase.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

const ChainCharacters = require("./");

const oldString = "THIS IS A STRING WITH UPPERCASE";
const oldString2 = "This Is a Test";


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

const result2 = new ChainCharacters(oldString2).toLowerCase();
console.assert(result2.value === oldString2.toLowerCase(), {
result: result2,
message: "Test 2 No pasado ",
});


Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,25 @@
//Tenemos que correr y asignar valores si el valor de oldString[i] es igual a valor de upperCase[]
// string[i]

function toUpperCase(string) {
const ChainCharacters = require("./constructor");

function toUpperCase() {
const lowerCase = "aábcdeéfghiíjklmnñoópqrstuúvwxyz.,- ";
const upperCase = "AÁBCDEÉFGHIÍJKLMNÑOÓPQRSTUÚVWXYZ.,- ";
let newString = "";

for (let i = 0; i < string.length; i++) {
for (let i = 0; i < this.length; i++) {
for (let j = 0; j < upperCase.length; j++) {
if (string[i] === lowerCase[j]) {
if (this.value[i] === lowerCase[j]) {
newString +=upperCase[j];
}
else if (string[i] === upperCase[j]) {
else if (this.value[i] === upperCase[j]) {
newString += upperCase[j];
}
}

}
return newString;
return new ChainCharacters(newString);
}

const oldString = "this is a lower case string";
const oldString2 = "This Is a Test";


const result1 = toUpperCase(oldString);
console.assert(result1 === oldString.toUpperCase(),{
result: result1,
message: "Test 1 No pasado ",
});

const result2 = toUpperCase(oldString2);
console.assert(result2 === oldString2.toUpperCase(), {
result: result2,
message: "Test 2 No pasado ",
});




module.exports = toUpperCase;
21 changes: 21 additions & 0 deletions staff/carlos-bock/chain-characters/toUpperCase.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

const ChainCharacters = require("./");

const oldString = "this is a lower case string";
const oldString2 = "This Is a Test";


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

const result2 = new ChainCharacters(oldString2).toUpperCase();
console.assert(result2.value === oldString2.toUpperCase(), {
result: result2,
message: "Test 2 No pasado ",
});



25 changes: 10 additions & 15 deletions staff/carlos-bock/chain-characters/trim.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,32 @@
//Si character nos es espacio guardarlo
//retornar nuevo string

function trim(string){
const ChainCharacters = require("./constructor");

function trim(){
let newString = "";
let index = 0;
let lastIndex = 0
for (let i = 0; i < string.length; i++) {
if (string[i] !== " ") {
for (let i = 0; i < this.length; i++) {
if (this.value[i] !== " ") {
index = i;
break;
//newString += string[i];
}
}

for (let i = string.length-1; i > 0; i--) {
if (string[i] !== " ") {
for (let i = this.length-1; i > 0; i--) {
if (this.value[i] !== " ") {
lastIndex = i;
break;
}
}

for (let i = index; i <= lastIndex; i++) {
newString += string[i];
newString += this.value[i];
}

return newString;
return new ChainCharacters(newString);
}


const oldString = " Este es un string ";

const result1 = trim(oldString);
console.assert(result1 === oldString.trim(),{
result: result1,
message: "Test 1 No pasado ",
});
module.exports = trim;
Loading

0 comments on commit 646ff49

Please sign in to comment.