Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions 09_Day_Higher_order_functions/09_day_starter/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>30DaysOfJavaScript:09 Day </title>
</head>

<body>
<h1>30DaysOfJavaScript:09 Day</h1>
<h2>Functional Programming</h2>

<script src="./data/countries_data.js"></script>
<script src="./scripts/main.js"></script>

</body>

</html>
<head>
<title>30DaysOfJavaScript:09 Day</title>
</head>

<body>
<h1>30DaysOfJavaScript:09 Day</h1>
<h2>Functional Programming</h2>

<script src="./data/countries_data.js"></script>
<script src="./scripts/main.js"></script>
</body>
</html>
124 changes: 122 additions & 2 deletions 09_Day_Higher_order_functions/09_day_starter/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,122 @@
console.log(countries)
alert('Open the console and check if the countries has been loaded')
const countries2 = ['Finland', 'Sweden', 'Denmark', 'Norway', 'Iceland']
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const products = [
{ product: 'banana', price: 3 },
{ product: 'mango', price: 6 },
{ product: 'potato', price: ' ' },
{ product: 'avocado', price: 8 },
{ product: 'coffee', price: 10 },
{ product: 'tea', price: '' },
]

//Task1-easy
//Task2-easy
//Task3-easy
function callbackCountries(element) {
console.log(element)
}

countries2.forEach(callbackCountries)

//Task4-easy
names.forEach(elem => {
console.log(elem)
})

//Task5-easy
numbers.forEach(elem => {
console.log(elem)
})

//Task6-easy
const newCountries2 = countries2.map(country => country.toLocaleUpperCase())
console.log(newCountries2)

//Task7-easy
const lengthCountries2 = countries2.map(elem => elem.length)
console.log(lengthCountries2)

//Task8-easy
const numbersSqr = numbers.map(num => num * num)
console.log(numbersSqr)

//Task9easy
const namesUpperCase = names.map(name => name.toUpperCase)
console.log(namesUpperCase)

//Task10-easy
const price = products.map(
product => `Price of ${product.product} = ${product.price}`
)
console.log(price)

//Task11-easy
const countriesWithLand = countries2.filter(country => country.includes('land'))
console.log(countriesWithLand)

//Task12-easy
const countriesSix = countries2.filter(country => country.length == 6)
console.log(countriesSix)

//Task13-easy
const countriesSixAndMore = countries2.filter(country => country.length >= 6)
console.log(countriesSixAndMore)

//Task14-easy
const countriesStartsWithE = countries2.filter(country => country[0] == 'E')
console.log(countriesStartsWithE)

//Task15-easy
const priceWithValue = products.filter(
product => typeof product.price == 'number'
)
console.log(priceWithValue)

//Task16-easy
const arr = [1, 'string', 'lntlns', 'lekj', 590]

function getStringLists(array) {
const newArray = array.filter(elem => typeof elem == 'string')

return newArray
}
console.log(getStringLists(arr))

//Task17-easy
const sum = numbers.reduce((acc, cur) => acc + cur)
console.log(sum)

//Task18-easy
const countriesToString = countries2.reduce((acc, cur, index) => index != countries2.length - 1 ? acc.concat(`, ${cur}`) : acc.concat(`, and ${cur} are north European countries`))
console.log(countriesToString)

//Task19-easy
//Task20-easy
const namesLength = names.some(name => name.length > 7)
console.log(namesLength)

//Task21-easy
const countriesContainsLand = countries2.every(country =>
country.includes('land')
)
console.log(countriesContainsLand)

//Task22-easy
//Task23-easy
const countryWithSixLetters = countries2.find(country => country.length == 6)
console.log(countryWithSixLetters)

//Task24-easy
const countryWithSixLetters2 = countries2.findIndex(
country => country.length == 6
)
console.log(countryWithSixLetters2)

//Task25-easy
const norwayPosition = countries2.findIndex(country => country == 'Norway')
console.log(norwayPosition)

//Task26-easy
const russiaPosition = countries2.findIndex(country => country == 'Russia')
console.log(russiaPosition)
2 changes: 1 addition & 1 deletion 10_Day_Sets_and_Maps/10_day_starter/data/countries_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ const countries = [
},
{
name: 'United States Minor Outlying Islands',
capital: '',
capital: '',f
languages: ['English'],
population: 300,
flag: 'https://restcountries.eu/data/umi.svg',
Expand Down
65 changes: 63 additions & 2 deletions 10_Day_Sets_and_Maps/10_day_starter/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,63 @@
console.log(countries)
alert('Open the console and check if the countries has been loaded')
//Task1-easy
const empty = new Set()
console.log(empty)

//Task2-easy
const numbers = new Set()

for (let i = 0; i <= 10; i++) {
numbers.add(i)
}

console.log(numbers)

//Task3-easy
numbers.delete(1)
console.log(numbers)

//Task4-easy
numbers.clear()
console.log(numbers)

//Task5-easy
const words = ['hello', 'text', 'hello', 'plant', 'tree']

const wordsSet = new Set(words)

console.log(wordsSet)

//Task6-easy
const countries3 = ['Finland', 'Sweden', 'Norway']

const countriesMap = new Map()

for (let i = 0; i <= countries3.length - 1; i++) {
countriesMap.set(countries3[i], countries3[i].length)
}

//Task1-medium
const a = [4, 5, 8, 9]
const b = [3, 4, 5, 7]

const A = new Set(a)
const B = new Set(b)

let c = new Set([...a, ...b])

console.log(c)

//Task2-medium
c = new Set(a.filter(num => B.has(num)))
console.log(c)

//Task3-medium
c = new Set(a.filter(num => !B.has(num)))
console.log(c)

console.log(countriesMap)

//Task1-hard
console.log(countries.length)

//Task2-hard
function mostSpokenLanguages(countries, n) {}