Skip to content

Instantly share code, notes, and snippets.

function sum(...theArgs) {
return theArgs.reduce((previous, current) => {
return previous + current;
});
}
console.log(sum(1, 2, 3)) // 6
// expected output: 6
console.log(sum(1, 2, 3, 4)) // 10
// let's separate Hansel from the rest, he will be put in the cage
const people = { Hansel: { age: 14 }, Gretel: { age: 10 }, Witch: { age: 99 } }
const { Hansel, ...rest } = people
console.log(Hansel) // { age: 14 }
console.log(rest) // { Gretel: { age: 10 }, Witch: { age: 99 } }
// let's draw cards from a deck
const deckOfCards = ['sevenOfClubs', 'aceOfSpades', 'queenOfHearts']
// let's add out dice in a game
const dicePool = [5, 2, 4]
const firstDiceThrow = [1, 4, 6]
const secondDiceThrow = [3, 6, 1]
console.log(dicePool) // [5, 2, 4]
dicePool.push(...firstDiceThrow, ...secondDiceThrow)
console.log(dicePool) // [5, 2, 4, 1, 4, 6, 3, 6, 1]
// create a cube from a square
const square = { x: 5, y: 10 }
const cube = { ...square, z: 12 }
console.log(square) // { x: 5, y: 10 }
console.log(cube) // { x: 5, y: 10, z: 12 }
cube.x = 10
console.log(square) // { x: 5, y: 10 }
// our base for making copies
const baseUnit = {
movement: 10,
hp: 100,
attributes: {
str: 12,
dex: 8,
con: 18,
},
}
// our NewWorldComponent.jsx
const NewWorldComponent = (props) => {
const { targetWorld } = props
return (
<div>
Hello {targetWorld}!
</div>
)
}
// our SpecialLink.jsx
const SpecialLink = (props) => {
const { url, label, ...additionalProps } = props
return (
<a href={url} ...additionalProps>
{label}
</a>
)
}
import React from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import SceneSplash from '../scenes/auth/sceneSplash'
const Stack = createStackNavigator()
const Navigation = () => (
<NavigationContainer>
<Stack.Navigator>
import React from 'react';
import { Provider } from 'react-redux'
import { enableScreens } from 'react-native-screens';
import configureStore from './src/redux/store'
import { initialiseApplication } from './src/redux/actions/application.actions'
import Navigation from './src/navigation'
enableScreens();
const store = configureStore()
// src/components/other/VersionTag.jsx
import React from 'react'
import { Text } from 'react-native'
import { connect } from 'react-redux'
const VersionTag = ({ applicationState: { version, name } }) => (
<Text>{`${name} (v${version})`}</Text>
)
const mapStateToProps = (state) => ({