This file contains 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 animal: 'dog' | 'tiger' | 'lion' = 'dog'; | |
const printDomesticAnimal = (animal: 'dog' | 'cat') => { | |
return animal; | |
} | |
printDomesticAnimal('tiger'); // bringing the tiger as tiger will be a problem | |
printDomesticAnimal('tiger' as 'dog'); // bringing the tiger as a dog |
This file contains 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 filterPostsByPageIndex = (posts, pageIndex) => { | |
const postPerPage = 5; | |
// get the total posts from page 1 to current page | |
const totalPagePosts = pageIndex * postPerPage; | |
// get the total posts from page 1 to previous page | |
const prevPagePosts = totalPagePosts - postPerPage; | |
return posts.filter( | |
(post, index) => index < totalPagePosts && index >= prevPagePosts |
This file contains 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
// what will it log | |
function foo(x) { | |
return function() { | |
x++; | |
console.log(x) | |
} | |
}; | |
const x = 0; | |
const bar = foo(x); |
This file contains 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
{ | |
"Styled components file": { | |
"prefix": "stc", | |
"body": [ | |
"import styled from 'styled-components'\n\nexport const ${1:${TM_FILENAME_BASE}} = styled.${2:div}`\n$0\n`;" | |
] | |
}, | |
"Styled component": { | |
"prefix": "btc", | |
"body": ["export const ${1:Div} = styled.${2:div}`\n$0\n`;"] |
This file contains 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
# guess number game for computers | |
import random as rd | |
# def guess_number(): | |
# user_input = int(input('Enter a number for computer to guess btw 1 and 10 (inclusive): ')) | |
# attempts = 2 | |
# | |
# while attempts >= 0: | |
# is_wrong = compare_guess(user_input, attempts) |
This file contains 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
# password generator | |
import random as rd | |
alphabets = 'abcdefghijklmnopqrstuvwxyz' | |
numbers = '1234567890' | |
characters = '!@#$%^&*~' | |
def generate_random_char(): |
This file contains 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
# guess the number game. (computers) | |
import random as rd | |
def guess_number(): | |
user_input = int(input('Enter a number for computer to guess btw 1 and 10 (inclusive): ')) | |
attempts = 2 | |
while attempts >= 0: |
This file contains 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
# guess the number game. | |
import random as rd | |
def guess_number(): | |
computer_input = rd.randint(1, 10) | |
attempts = 2 | |
while attempts >= 0: |
This file contains 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 removeProps = (obj, ...propsName) => { | |
propsName.forEach((propName) => { | |
delete obj[propName] | |
}) | |
} |
This file contains 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
# Write a Python program to calculate number of days between two dates. | |
# (2014, 7, 2), (2014, 7, 11) | |
import datetime as date | |
def num_of_days(date_one, date_two): | |
try: | |
(year, month, day) = date_one | |
new_date = date.datetime(year, month, day).timestamp() |
NewerOlder