Remove duplicates
let nums =[1,2,2,3] // [1,2,3]
console.log([..new Set(nums)]);
---------------------------
console.log(5<6<7);// true
console.log(7<6<5);// flase
------------------------------------------------------------
A - Function countAlphabets(String)
<script>
function getFrequency(str) {
return str.split('').reduce( (prev, curr) => {
prev[curr] = prev[curr] ? prev[curr] + 1 : 1;
return prev;
}, {});
};
console.log(getFrequency('malayalam'));
</script>
<script>
function getFrequency(str) {
return str.split('').reduce((total, letter) => {
total[letter] ? total[letter]++ : total[letter] = 1;
return total;
}, {});
};
console.log(getFrequency('aabbccdd'));
</script>
--------------------------------------------------------------------------------------
var x = prompt("enter number", "7");
var i = 0;
var binaryvar = " ";
function add(n) {
if (n == 0) {
binaryvar = "0" + binaryvar;
}
else {
binaryvar = "1" + binaryvar;
}
}
function binary() {
while (i < 1) {
if (x == 1) {
add(1);
document.write(binaryvar);
break;
}
else {
if (x % 2 == 0) {
x = x / 2;
add(0);
}
else {
x = (x - 1) / 2;
add(1);
}
}
}
}
binary();
---------------------------------------------------
let nums =[1,2,2,3] // [1,2,3]
console.log([..new Set(nums)]);
---------------------------
console.log(5<6<7);// true
console.log(7<6<5);// flase
------------------------------------------------------------
A - Function countAlphabets(String)
<script>
function getFrequency(str) {
return str.split('').reduce( (prev, curr) => {
prev[curr] = prev[curr] ? prev[curr] + 1 : 1;
return prev;
}, {});
};
console.log(getFrequency('malayalam'));
</script>
<script>
function getFrequency(str) {
return str.split('').reduce((total, letter) => {
total[letter] ? total[letter]++ : total[letter] = 1;
return total;
}, {});
};
console.log(getFrequency('aabbccdd'));
</script>
--------------------------------------------------------------------------------------
var x = prompt("enter number", "7");
var i = 0;
var binaryvar = " ";
function add(n) {
if (n == 0) {
binaryvar = "0" + binaryvar;
}
else {
binaryvar = "1" + binaryvar;
}
}
function binary() {
while (i < 1) {
if (x == 1) {
add(1);
document.write(binaryvar);
break;
}
else {
if (x % 2 == 0) {
x = x / 2;
add(0);
}
else {
x = (x - 1) / 2;
add(1);
}
}
}
}
binary();
---------------------------------------------------