Published
Edited
Jul 11, 2018
2 stars
Insert cell
Insert cell
Insert cell
{
const hof = myOwnCallback => {
console.log('myOwnCallback is - ', myOwnCallback)
myOwnCallback(5)
}
const f = x => 2 * x
return hof('ala')
}
Insert cell
{
const hof = myOwnCallback => {
console.log('myOwnCallback is - ', myOwnCallback)
myOwnCallback(5)
}
const f = x => 2 * x
return hof(f(10))
}
Insert cell
{
const hof = myOwnCallback => {
console.log('myOwnCallback is - ', myOwnCallback)
return myOwnCallback(5)
}
const f = x => 2 * x
return hof(f)
}
Insert cell
Insert cell
{
const hof = myOwnCallback => myOwnCallback(5)
const f = x => 2 * x
return hof(f)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
numbers.forEach((el, i, arr) => {
console.log(el)
})
}
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
numbers.forEach(el => console.log(el))
}
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
numbers.forEach(number => console.log(number))
}
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
const resultOfForEach = numbers.forEach(number => console.log(number))
return resultOfForEach
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
let sum = 0
for(let i = 0; i < numbers.length; i++){
sum += numbers[i]
}
return sum
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
let sum = 0
numbers.forEach(number => sum += number)
return sum
}
Insert cell
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.map((el, i, arr) => 'Element ' + i + ' o wartości ' + el)
}
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
const newArray = numbers.map(number => number * 2)
return newArray
}
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
const newArray = numbers.map(number => number * 2)
return numbers
}
Insert cell
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.filter((el, i, arr) => el > 10)
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.filter((el, i, arr) => el > 10 && el < 80)
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.filter((el, i, arr) => true)
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.filter((el, i, arr) => false)
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.filter((el, i, arr) => 1)
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.filter((el, i, arr) => 0)
}
Insert cell
Insert cell
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.find((el, i, arr) => el > 10 && el < 80)
}
Insert cell
{
const numbers = [10, 5, 87, 19, 99, 15]
return numbers.find((el, i, arr) => el > 10 && el < 15) // there no elements greater than 10 and less than 15
}
Insert cell
Insert cell
Insert cell
{
const numbers = [1,2,3]
const sum = numbers.reduce(
(reduced, number, i, arr) => reduced + number, // we MUST return new reduced value for next call
0
)

return sum
}
Insert cell
{
const numbers = [123, 353464, 86, 3]
return numbers.reduce((r, el) => r + el)
}
Insert cell
{
const names = ['Ala', 'Ela', 'Ilona']
return names.reduce((reduced, name, i, arr) => reduced + name + (i === arr.length - 1 ? '.' : ' '), '')
}
Insert cell
Insert cell
{
const numbers = [1.5, 2, 5.5, 1, 6, 10]
return numbers
.map(number => number * 2)
.filter(number => number % 2 === 0)
.reduce((r, el) => r + el)
}
Insert cell
{
const numbers = [1.5, 2, 5.5, 1, 6, 10]
const add = (a, b) => a + b
const even = x => x % 2 === 0
return numbers
.map(number => number * 2)
.filter(even)
.reduce(add)
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more