The most viewed items
const tnwNames = ["Moe", "Soe", "Noe", "Mya"];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNames.join(", ");
}
function tnwFun2(){
document.getElementById("demo").innerHTML = "The original array is : " + tnwNames.join(", ");
let tnwNewvalue = document.getElementById("newname").value;
tnwNames.unshift(tnwNewvalue);
document.getElementById("demo1").innerHTML = "The new array is : " + tnwNames.join(", ");
}
const tnwNames = ["Hla", "Mya", "Soe", "Moe", "Noe"];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNames.join(", ");
}
function tnwFun2(){
document.getElementById("demo").innerHTML = "The original array is :
" + tnwNames.join(", ");
let result = tnwNames.splice(2, 2, "Aung", "Kyaw", "Tun");
document.getElementById("demo1").innerHTML = "The removed elements are :
" + result.join(", ");
document.getElementById("demo2").innerHTML = "The new array is :
" + tnwNames.join(", ");
}
//1. sort alphabetically
/**
const countries = ["Myanmar", "Singapore", "Malaysia", "USA", "Thailand", "Vietname"];
function tnwFun1(){
document.getElementById("demo").innerHTML = countries.join("
");
}
function jsSort(){
let result = countries.sort();
document.getElementById("demo").innerHTML = result.join("
");
}
function jsReverse(){
let result = countries.reverse();
document.getElementById("demo").innerHTML = result.join("
");
}
//2. Sort randomly
const tnwNums = [20, 17, 30, 38, 40, 50, 28, 12];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNums.join("
");
}
function tnwFun2(){
let result = tnwNums.sort(tnwFun3);
document.getElementById("demo").innerHTML = result.join("
");
}
function tnwFun3(a, b){
return 0.5 - Math.random();
} */
// 3. Sort Numerically
const tnwNums = [20, 17, 30, 38, 40, 50, 28, 12, 4];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNums.join("
");
}
function jsSort(){
let result = tnwNums.sort(function(a, b){return a - b;});
document.getElementById("demo").innerHTML = result.join("
");
}
function jsReverse(){
let result = tnwNums.sort(function(a, b){return b - a;});
document.getElementById("demo").innerHTML = result.join("
");
}
const tnwNums = [20, 39, 48, 58, 68, 70, 85, 90];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNums.join(", ");
}
function tnwFun2(){
let result = tnwNums.some(tnwFun3);
document.getElementById("demo").innerHTML = tnwNums.join(", ");
document.getElementById("demo1").innerHTML = result;
}
function tnwFun3(num){
let chkInput = document.getElementById("chknum").value;
return num > chkInput;
}
const tnwNums = [20, 29, 30, 39, 40, 47, 50, 70];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNums.join(", ");
}
function tnwFun2(){
let result = tnwNums.slice(1, 4);
document.getElementById("demo").innerHTML = "The original is: " + tnwNums.join(", ");
document.getElementById("demo1").innerHTML = "The new array is: " + result.join(", ");
}
const tnwNums = [20, 30, 40, 50, 60, 70, 90];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNums.join(", ");
}
function tnwFun2(){
let result = tnwNums.shift();
document.getElementById("demo").innerHTML = tnwNums.join(", ");
document.getElementById("demo1").innerHTML = "The removed element is: " + result;
}
const tnwNums = [20, 30, 40, 50, 60, 70];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNums.join("
");
}
function tnwFun2(){
let result = tnwNums.reverse();
document.getElementById("demo").innerHTML = result.join("
");
}
const tnwNum = [20, 9, 20, 8, 100];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNum.join(", ");
}
function tnwFun2(){
var result = tnwNum.reduceRight(tnwFun3);
document.getElementById("demo").innerHTML = result;
}
function tnwFun3(numRight, sum){
return numRight - sum;
}
const tnwNum = [70, 30, 20, 10, 7];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNum.join("
");
}
function tnwFun2(){
var result = tnwNum.reduce(tnwFun3);
document.getElementById("demo").innerHTML = result;
}
function tnwFun3(leftNum, sum){
return leftNum - sum;
}
const tnwNames = ["Soe Soe", "Moe Moe"];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNames.join("
");
}
function tnwFun2(){
let tnwAdd = document.getElementById("adding").value;
let result = tnwNames.push(tnwAdd);
document.getElementById("demo").innerHTML = result;
}
const tnwName = ["Hla Hla", "Mya Mya", "Aung Aung", "Maung Maung"];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwName.join("
");
}
function tnwFun2(){
let result = tnwName.pop();
document.getElementById("demo").innerHTML = "The removed element is : " + result;
}
const tnwNum = [10, 20, 30, 40];
function tnwFun1(){
document.getElementById("demo").innerHTML = tnwNum.join("
");
}
/**
function tnwFun2(){
let result = tnwNum.map(Math.sqrt);
document.getElementById("demo").innerHTML = result.join("
");
}*/
function tnwFun2(){
let result = tnwNum.map(tnwFun3);
document.getElementById("demo").innerHTML = result.join("
");
}
function tnwFun3(num){
return num * 10;
}