visit
Input:
integer?
float?
string?
str("Hello There Blogue IS A BEauTIFUL %^$##@1144 !!!!!$%#")
Output:
integer?
float?
string?
result: { h: 2, e: 3, l: 2, o: 2, t: 1, r: 1, f: 1, u: 2, c: 1, k: 1, y: 1 }
//example1
let str = '';
for (let i = 0; i < 9; i++) {
str = str + i;
}
console.log(str);
//example2
const sentence = 'The quick brown fox jumps over the lazy dog.';
console.log(sentence.toLowerCase());
//example3
function testNum(a) {
let result;
if (a > 0) {
result = 'positive';
} else {
result = 'NOT positive';
}
return result;
}
function countValues(str){
var result = {};
for(var i=0;i<str.length;i++)
{
var chara = str[i].toLowerCase();
//conversion of string to lowercase as the same letter is in small and in capital,we don' want that
if(result[chara]>0){
result[chara]++;
//increments the count if condition is grater than 0;
}else{
//else makes it 1
result[chara] = 1;
}
}
}
console.log(result) ;
}
countValues("Hello There Blogue IS A BEauTIFUL %^$##@1144 !!!!!$%#")
function countValues(str){
var result = {};
//for(var i=0;i<str.length;i++)
for(var chara of str)
{
//var chara = str[i].toLowerCase();
chara = chara.toLowerCase();
//R.E to check lowercase and number
if(/[a-z0-9]/.test(chara)){
result[chara] = ++result[chara] || 1;
// if(result[chara]>0){
// result[chara]++;
// }else{
// result[chara] = 1;
// }
}
}
console.log(result) ;
}
countValues("Hello There Blogue IS A BEauTIFUL %^$##@1144 !!!!!$%#")
function countValues(str){
var result = {};
for(var chara of str){
if(isAlphaNumeric(chara)){
chara = chara.toLowerCase();
result[chara] = ++result[chara] || 1;
}
}
console.log(result) ;
}
function isAlphaNumeric(chara){
var code = chara.charCodeAt(0);
if(!(code > 47 && code < 58)&& !(code > 64 && code < 91)&& !(code > 96 && code < 123))
{
return false;
}
return true;
}
countValues("Hello There Blogue IS A BEauTIFUL %^$##@1144 !!!!!$%#")
Previously published at .