This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pick(obj, props) { | |
return props.reduce(function(result, prop) { | |
result[prop] = obj[prop]; | |
return result; | |
}, {}); | |
} | |
const person = { | |
name: 'Jonathan', | |
age: 21, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { name, age, gender } = { | |
name: 'Jonathan', | |
age: 21, | |
gender: 'male' | |
}; | |
console.log(name); // Outputs 'Jonathan' | |
console.log(age); // Outputs '21' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zipObject(keys, values) { | |
return keys.reduce((obj, key, i) => { | |
obj[key] = values[i]; | |
return obj; | |
}, {}); | |
} | |
const fruits = zipObject(['apple', 'pears', 'bananas'], [1, 2, 3]); | |
console.log(fruits); // Result { apple: 1, pears: 2, bananas: 3 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function omit(obj, omitList = []) { | |
const result = { ...obj }; | |
omitList.forEach((prop) => { | |
delete result[prop]; | |
}); | |
return result; | |
} | |
const person = { | |
name: 'Jonathan', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
name: 'Jonathan', | |
age: 21, | |
gender: 'male' | |
} | |
console.log(Object.entries(person)); | |
// Result [ [ 'name', 'Jonathan' ], [ 'age', 21 ], [ 'gender', 'male' ] ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
name: 'Jonathan', | |
age: 21, | |
gender: 'male' | |
} | |
console.log(Object.values(person)); // Result [ 'Jonathan', 21, 'male' ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
name: 'Jonathan', | |
age: 21, | |
gender: 'male' | |
} | |
console.log(Object.keys(person)); // Result [ 'name', 'age', 'gender' ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const obj1 = { | |
name: 'Jonathan', | |
age: 21 | |
} | |
const obj2 = { | |
name: 'Jonathan', | |
gender: 'male' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fruits = [ | |
{ | |
id: 1, | |
name: 'apple' | |
}, | |
{ | |
id: 2, | |
name: 'banana' | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
func main() { | |
var str string |
NewerOlder