No entiendo lo que hago mal, no funciona pero no encuentro otra manera :S
Código HTML:
Ver original
<input href="#" class="myButton" type="button" value="Start" onClick="array_count_values(texto);">
Código Javascript
:
Ver originalfunction array_count_values(texto) {
var array = texto.value.trim().replace(sim, ' ').split(' ').length;
var tmp_arr = {};
key = '';
t = '';
var __getType = function(obj) {
var t = typeof obj;
t = t.toLowerCase();
if (t === 'object') {
t = 'array';
}
return t;
};
var __countValue = function(value) {
switch (typeof value) {
case 'number':
if (Math.floor(value) !== value) {
return;
}
case 'string':
if (value in this && this.hasOwnProperty(value)) {
++this[value];
} else {
this[value] = 1;
}
}
};
t = __getType(array);
if (t === 'array') {
for (key in array) {
if (array.hasOwnProperty(key)) {
__countValue.call(tmp_arr, array[key]);
}
}
}
console.log(texto.match(/\s+/g));
var valores = [];
for (var i in tmp_arr) valores.push("La palabra '" + i + "' se repite " + tmp_arr[i] + " vez/veces");
alert(valores.join("\n") + "\n\nHay " + (texto.match(/\s+/g).length) + " espacios" + "\nHay " + array.length + " palabras");
}