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 minimumDistances(numbers) { | |
| const numberQuantity = numbers.length; | |
| const firstOccurrences = {}; | |
| let minDistance = Infinity; | |
| for (let idx = 0; idx < numberQuantity; idx += 1) { | |
| const num = numbers[idx]; | |
| const firstOccurrenceIdx = firstOccurrences[num]; | |
| if (firstOccurrenceIdx === undefined) { |
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 convertTimeDiff = diff => ({ | |
| dd: Math.floor(diff / (1000 * 60 * 60 * 24)), | |
| hh: Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)), | |
| mm: Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)), | |
| ss: Math.floor((diff % (1000 * 60)) / 1000) | |
| }); | |
| const useTimer = timestamp => { | |
| const [timer, setTimer] = useState(null); |
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 array0 = [1, 2]; | |
| const array1 = [array0, [3, 4]]; | |
| const array2 = [array0, [3, 4]]; | |
| console.log(array1.filter(x => array2.includes(x))); // [[1, 2]] |
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
| […Array(10)].map((_, idx) => moment().add(idx, 'year').format('YYYY')); |
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 isChanged<ValueType>(change: ChangeRecord<ValueType>){ | |
| return change.oldValue !== change.newValue; | |
| } |
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 reverseString = (inputStr) => inputStr.split('').reverse().join(''); |
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 arr = [1, 0, 2, 3, 1, 0]; | |
| // Oops, we have an empty array | |
| const newArray = arr.filter(item => { | |
| if (item === 0) { return item } | |
| }); | |
| // This works properly | |
| const filteredArray = arr.filter(item => item === 0); |
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
| // Can handle only simple keys | |
| const logValues1 = (obj, keys) => { | |
| keys.forEach(key => console.log(obj[key])); | |
| } | |
| // Can handle complex keys | |
| const logValues2 = (obj, keys) => { | |
| keys.forEach(key => console.log(_.at(obj, key))); | |
| } |
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
| Pet.propTypes = { | |
| pet: PropTypes.shape({ | |
| age: PropTypes.number, | |
| color: PropTypes.string, | |
| name: PropTypes.string | |
| }) | |
| }; |
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 stylesObject = { | |
| wrapper: { | |
| 'background': 'linear-gradient(135deg, #aa00ff 0%,#6a1b9a 100%)', | |
| 'border-radius': '4px', | |
| }, | |
| } | |
| const styles = Object.fromEntries(Object.entries(stylesObject).map(([element, style]) => [element, getStyles(style)])); | |
| <div style="${styles.wrapper}"> |
NewerOlder