Ver Mensaje Individual
  #19 (permalink)  
Antiguo 28/10/2014, 16:12
Avatar de IsaBelM
IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Contar cantidad de oraciones y parrafos en textarea

a parte de
Cita:
Iniciado por rodrypaladin Ver Mensaje
me gustaría que el texto el cual tiene que contar lo pille directamente del value del textarea. Y que si es posible solamente muestre los 15 primeros valores ( es decir las 15 palabras que más se repiten )
puedes hacer que se muestren en orden ascendente o descendente por el número de repeticiones
Código:
    Array.prototype.EliminarRepetidos = function () {
var ordenar = [];
    var arr_limpio = [];
    var cantidad = {};
        for(var i = 0; i < this.length; i++){
            if(!(this[i] in cantidad)) {
                cantidad[this[i]] = 0;
                arr_limpio.push(this[i]);
                cantidad[this[i]]++;
            } else {
                cantidad[this[i]]++;
            }
        }
     


        for (j=0; j < arr_limpio.length; j++) {

            var obj = new Object();
            obj.palabra = arr_limpio[j];
            obj.repeticion = cantidad[arr_limpio[j]];

            ordenar.push(obj);
        }


        ordenar.sort(function (a, b) {

            if (a.repeticion > b.repeticion) {
                 return 1;
            }

            if (a.repeticion < b.repeticion) {
                 return -1;
            }

            return 0;
        });


var repeticiones = "";
    if (ordenar.length > 3) var max = 3; // SE MOSTRARÁN LAS 3 PRIMERAS
        for (x=0; x< max; x++) {

            repeticiones += ordenar[x].palabra + ": " + ordenar[x].repeticion + "<br/>";
            
            document.getElementById("espacio").innerHTML = repeticiones;
        }
        
    }
     
     
    function ContarRepetidos() {
    var val = document.getElementById("area").value;
    array = val.split(' ');
    obj = array.EliminarRepetidos();
    }
 
    </script>
    </head>
    <body>
    <h1>Elementos repetidos..</h1>
    <textarea id="area">hola hola hola adios adios adios tal tal pepe</textarea>
    <input type="button" value="ver" onclick="ContarRepetidos();" />
    <div id="espacio"></div>
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}