Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active March 14, 2018 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ed804041507156da9a8c62dc0c9bfd3e to your computer and use it in GitHub Desktop.
Save parzibyte/ed804041507156da9a8c62dc0c9bfd3e to your computer and use it in GitHub Desktop.
$scope.comenzar = textoOriginal => {
if (!textoOriginal) return;
$scope.haComenzado = true;
let textoComoArreglo = textoOriginal
.replace(/[áéíóúñ]/g, coincidencia => {
return {
á: "a",
é: "e",
í: "i",
ó: "o",
ú: "u",
ñ: "n"
}[coincidencia];
})
.replace(/\W+/g, " ")
.toLowerCase()
.split(" "),
contador = 0,
textoModificado = [];
textoComoArreglo.forEach(palabra => {
if (
$scope.deberiaBorrarEstaPalabra() &&
contador < $scope.minimaSeparacionEntreInputs
) {
contador++;
textoModificado.push({
palabraOriginal: palabra,
palabraIntroducida: ""
});
} else {
textoModificado.push({
palabra: palabra
});
if (contador > 0) contador--;
}
});
$scope.textoModificado = textoModificado;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment