//input user_name_Km outout userNameKm
function getVariableName(inp) {
let output = '';
if (inp.indexOf('_') != -1) {
var splitArr = inp.split("_");
let i = 1;
if (splitArr[0] === '') {
i = 2;
output += splitArr[1].toLowerCase();
}
else
output += splitArr[0].toLowerCase();
for (let j = i; j < splitArr.length; j++) {
console.log(splitArr[j], splitArr[j].slice(1, splitArr[j].length));
output += splitArr[j][0].toUpperCase() + splitArr[j].slice(1, splitArr[j].length);
}
return console.log(inp, output);
}
for (let i = 0; i < inp.length; i++) {
console.log(inp[i].charCodeAt(), inp[i]);
if (inp[i].charCodeAt() <= 90)
output += '_' + inp[i].toUpperCase();
else output += inp[i];
}
console.log(inp, output);
}
getVariableName("user_name_Km");
getVariableName("_Nname_Km");
getVariableName("Nname_jm_U");
getVariableName("useUameKm");
getVariableName("userName");
getVariableName("YnameJmU");
//Binary to Decimal
var binary = "1101000";
binaryToDecimal(binary)
var digit = parseInt(binary, 2);
console.log(digit);
function binaryToDecimal(string) {
let decimal = 0;
let bits = 1;
for(let i = string.length-1; i >=0; i--) {
let currNum = (string[i]);
console.log(currNum,"currNum")
if(currNum === "1") {
decimal += bits;
}
bits *= 2;
console.log(bits,"bits",decimal)
}
console.log(decimal);
}
No comments:
Post a Comment