feat: add day 6

pull/593/head
hoangdev72 3 years ago
parent 4e58a20337
commit f924823038

@ -0,0 +1,188 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="../../data/countries.js"></script>
<script>
const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB'
]
const mernStack = ['MongoDB', 'Express', 'React', 'Node']
// Iterate 0 to 10 using for loop, do the same using while and do while loop
for(let i = 0; i <= 10; i++){
console.log(i)
}
let i = 0
while (i <= 10){
console.log(i)
i++
}
i = 0
do{
console.log(i)
i++
}while(i <= 10)
// Write a loop that makes the following pattern using console.log():
// #
// ##
// ###
// ####
// #####
// ######
// #######
for(let i = 1; i <= 7; i++){
for(let j = 1; j <= i; j++){
console.log("#")
}
console.log("\n")
}
// Use loop to print the following pattern:
// 0 x 0 = 0
// 1 x 1 = 1
// 2 x 2 = 4
// 3 x 3 = 9
// 4 x 4 = 16
// 5 x 5 = 25
// 6 x 6 = 36
// 7 x 7 = 49
// 8 x 8 = 64
// 9 x 9 = 81
// 10 x 10 = 100
for(let i = 0; i <= 10; i++){
console.log(`${i} x ${i} = ${i*i}\n`)
}
// Develop a small script which generate array of 5 random numbers
let ranArr = Array(5).fill().map(() => Math.random())
console.log(ranArr)
// Develop a small script which generate a six characters random id:
console.log(Math.random().toString(36).slice(-6));
// Develop a small script which generate any number of characters random id:
ranArr = Math.random().toString(36).substring(-12);
console.log(ranArr)
// ["ALBANIA", "BOLIVIA", "CANADA", "DENMARK", "ETHIOPIA", "FINLAND", "GERMANY", "HUNGARY", "IRELAND", "JAPAN", "KENYA"]
// Using the above countries array, create an array for countries length'.
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya'
]
const numbers = [7, 7, 6, 7, 8, 7, 7, 7, 7, 5, 5]
// Use the countries array to create the following array of arrays:
// [
// ['Albania', 'ALB', 7],
// ['Bolivia', 'BOL', 7],
// ['Canada', 'CAN', 6],
// ['Denmark', 'DEN', 7],
// ['Ethiopia', 'ETH', 8],
// ['Finland', 'FIN', 7],
// ['Germany', 'GER', 7],
// ['Hungary', 'HUN', 7],
// ['Ireland', 'IRE', 7],
// ['Iceland', 'ICE', 7],
// ['Japan', 'JAP', 5],
// ['Kenya', 'KEN', 5]
// ]
let result = []
countries.forEach((v, i) => {
result.push([v, v.slice(0, 3).toString().toUpperCase(), numbers[i]])
})
console.log(result)
// In above countries array, check if there is a country or countries containing the word 'land'. If there are countries containing 'land', print it as array. If there is no country containing the word 'land', print 'All these countries are without land'.
let arrOfCountries = []
countries.forEach((country) => {
if (country.includes('land')){
arrOfCountries.push(country)
}
})
switch(arrOfCountries.length){
case 0:
console.log('There are no country contain land')
break
case countries.length:
console.log('All are contain land')
break
default:
console.log(arrOfCountries)
}
// ['Finland','Ireland', 'Iceland']
// Using the above countries array, find the country containing the biggest number of characters.
let arrOfCountriesLength = countries.map(e => e.length)
console.log(countries[Math.max(...arrOfCountriesLength)])
// Using the above countries array, find the country containing only 5 characters.
console.log(countries.filter((e) => {
if (e.length == 5){
return e
}
}))
// Print all the elements of array as shown below.
const fullStack = [
['HTML', 'CSS', 'JS', 'React'],
['Node', 'Express', 'MongoDB']
]
// HTML
// CSS
// JS
// REACT
// NODE
// EXPRESS
// MONGODB
console.log(fullStack.forEach((v) => {
console.log(v.join("\n"))
}))
// Extract all the countries contain the word 'land' from the countries array and print it as array
console.log(countries1.filter(e => e.includes('land')))
// Find the country containing the hightest number of characters in the countries array
let maxLenInArr = Math.max(...countries1.map(e => e.length))
console.log(countries1.filter(e => e.length == maxLenInArr))
// Reverse the countries array and capitalize each country and stored it as an array
let reverseCountries = countries1.reverse().map(e => e.toUpperCase())
console.log(reverseCountries)
</script>
</body>
</html>

@ -1,4 +1,4 @@
const countries = [
const countries1 = [
'Afghanistan',
'Albania',
'Algeria',

Loading…
Cancel
Save