Skip to content

Instantly share code, notes, and snippets.

function doNothing(obj) {
return obj ? obj : obj
}
function doSomethingButNothingStill(obj) {
if (obj) {
obj = obj
}
return obj ? obj : obj
}
function doNothing(obj) {
return obj ? obj : obj
}
const result = doNothing({ name: 'Bob' })
{
"game1": {
"lakers": 80,
"celtics": 80,
"overtime": {
"lakers": 96,
"celtics": 116
}
},
"game2": {
function doubleTheNums(obj) {
const keys = Object.keys(obj)
for (let index = 0; index < keys.length; index++) {
const key = keys[index]
const value = obj[key]
if (typeof value === 'number') {
obj[key] = obj[key] * 2
} else if (value && typeof value === 'object') {
doubleTheNums(obj[key])
function doubleTheNums(obj) {
const keys = Object.keys(obj)
for (let index = 0; index < keys.length; index++) {
const key = keys[index]
const value = obj[key]
if (typeof value === 'number') {
obj[key] = obj[key] * 2
} else if (value && typeof value === 'object') {
doubleTheNums(obj[key])
{
"game1": {
"lakers": 80,
"celtics": 80,
"overtime": {
"lakers": 48,
"celtics": 58
}
},
"game2": {
function doubleTheNums(obj) {
const keys = Object.keys(obj)
for (let index = 0; index < keys.length; index++) {
const key = keys[index]
const innerObj = obj[key]
const innerObjKeys = Object.keys(innerObj)
for (let innerIndex = 0; innerIndex < innerObjKeys.length; innerIndex++) {
const innerObjKey = innerObjKeys[innerIndex]
const innerObjKeyValue = innerObj[innerObjKey]
function append(str, modify = (s) => s) {
return `hello ${modify(str)}`
}
function capitalize(value) {
return value.toUpperCase()
}
const result = append('boss', capitalize) // 'hello BOSS'
const f = console.log
const g = (str) => `Hello, ${str}`
const sayWord = (x) => f(g(x))
sayWord('bryan') // "Hello, bryan
class SomeElement<T> {
private element: T
constructor(element: T) {
this.element = element
}
getElement() {
return this.element
}