Skip to content

Instantly share code, notes, and snippets.

@ehudthelefthand
Created June 6, 2022 13:12
Show Gist options
  • Save ehudthelefthand/9fdfbf620862acb9f956396f5d2e9030 to your computer and use it in GitHub Desktop.
Save ehudthelefthand/9fdfbf620862acb9f956396f5d2e9030 to your computer and use it in GitHub Desktop.
PEA Node.js Class
console.log('hello world'.length)
console.log('hello world'.charAt(0))
console.log('hello world'.split(' '))
console.log('hello world'.substring(1, 7))
// 012345678910
console.log(1)
console.log(1.1)
console.log(1.1 + 1.3)
console.log(0.1 + 0.2)
console.log(2 ** 3)
console.log(Number('1101.23'))
console.log(typeof Number('1101.23'))
console.log(parseInt('1101.23', 10))
console.log(typeof parseInt('1101.23', 10))
console.log(parseFloat('1101.23'))
console.log(typeof parseFloat('1101.23'))
console.log(String(1101.23))
console.log(typeof String(1101.23))
console.log(`${1101.23 + 1.2}`)
console.log(typeof `${1101.23 + 1.2}`)
const number = 1101.23 + 1.2
console.log(`${number}`)
console.log(typeof `${number}`)
console.log(true)
console.log(false)
console.log(typeof false)
let a = 'hello'
console.log(a)
a = 'world'
console.log(a)
const b = 'hello'
console.log(b)
b = 'world'
console.log(b)
const numbers = [ 1, 2, 3, 4, 5 ]
console.log(numbers)
console.log(typeof numbers)
console.log(Array.isArray(numbers))
console.log(numbers[0])
console.log(numbers.length)
console.log(numbers.filter((n) => {
return n % 2 == 0
})) // Array A -> Array B (number of element B <= number of element A)
console.log(numbers.map((n) => {
return String(n)
})) // Array A -> Array B (type of element B is changed)
console.log(numbers.reduce((accumulate, current) => {
// 0 , 1
// 1 (0+1), 2
// 3 (1+2), 3
const value = {[`${current}`]: current}
return { ...accumulate, ...value }
})) // Array A -> Value
const a = [1,2,3,4,5]
const b = [...a]
const obj = {
name: 'Foobar',
age: 12,
single: false,
child: {
foo: 'bar'
}
}
console.log(obj)
console.log(typeof obj)
const newObj = { ...obj, child: 'foobar' }
console.log(newObj)
function add(a, b) {
return a + b
}
console.log(add(1, 2))
const add2 = (a, b) => {
return a + b
}
console.log(add2(1, 2))
const isEven1 = (a) => {
return a % 2 === 0
}
const isEven2 = a => a % 2 === 0
console.log(isEven1(2))
console.log(isEven2(3))
const addWith3orAny = (a, b = 3) => {
return a + b
}
console.log(addWith3orAny(1))
console.log(addWith3orAny(1, 2))
const muliply = (a, b) => a * b
const runFncAndPrint = (multiplyFn, printFn) => {
printFn(multiplyFn(2, 3))
}
runFncAndPrint(muliply, console.log)
const addWith = (a) => {
return (b) => {
return a + b
}
}
const addWith3 = addWith(3)
console.log(addWith3(3))
console.log(addWith3(4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment