Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions projects/003-string-edit-distance/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const prompt = require('prompt-sync')();

const calculateEditDostance = (firstString, secondString) => {
const emptyArr = [];

if (firstString === secondString) {
return 0;
}

for (let i = 0; i < firstString.length; i++) {
if (
firstString[i] !== secondString[i] &&
firstString.length >= secondString.length
) {
emptyArr.push(i);
}
}

for (let j = 0; j < secondString.length; j++) {
if (
firstString[j] !== secondString[j] &&
firstString.length < secondString.length
) {
emptyArr.push(j);
}
}
return emptyArr.length;
};

const firstString = prompt('Enter something');
const secondString = prompt('Enter something');
console.log(
` The edit distance between the two strings is equal to: ${calculateEditDostance(
firstString,
secondString
)}`
);

// if (firstString === secondString) {
// console.log(0); // caso base
// }
// for (let i = 0; i < firstString.length; i++) {
// if (
// firstString[i] !== secondString[i] &&
// firstString.length >= secondString.length
// ) {
// emptyArr.push(i);
// }
// }

// for (let j = 0; j < secondString.length; j++) {
// if (
// firstString[j] !== secondString[j] &&
// firstString.length < secondString.length
// ) {
// emptyArr.push(j);
// }
// }

// // console.log(emptyArr);
// console.log(emptyArr.length);