Skip to content

Instantly share code, notes, and snippets.

View mgmgpyaesonewin's full-sized avatar
🐒
coding

Pyae Sone Win mgmgpyaesonewin

🐒
coding
View GitHub Profile
@mgmgpyaesonewin
mgmgpyaesonewin / sum.js
Last active May 9, 2018 07:42
Finding the total number of item in a array
sum: function(arr) {
return arr.reduce( (total, num) => total + num, 0);
}
@mgmgpyaesonewin
mgmgpyaesonewin / indexOf.js
Created December 20, 2017 04:38
determine the location of an item in an array
indexOf: function(arr, item) {
return arr.indexOf(item);
}
@mgmgpyaesonewin
mgmgpyaesonewin / hackerrank.js
Created December 20, 2017 07:44
How to read line by line of data input in hackerank
function processData(input) {
//Enter your code here
var data = input.toString().split(/\r?\n/);
console.log(data[0]);
console.log(data[1]);
console.log(data[2]);
}
@mgmgpyaesonewin
mgmgpyaesonewin / list.scss
Created January 3, 2018 11:48
Sample Hover in SCSS with styled component react example
const List = styled.div`
border-bottom: 1px solid rgba(120, 130, 140, 0.13);
padding: 10px 15px;
&:last-child {
border: none;
}
&:hover {
background: #f7fafc;
}
`;
const Row = styled.div`
display: flex;
align-items: center;
flex-flow: row wrap;
padding: 16px 0 8px;
> * {
flex: 1 100%;
}
@mgmgpyaesonewin
mgmgpyaesonewin / getAndCache.js
Created January 18, 2018 06:59
Getting data from backend redux
import cache from 'memory-cache';
const getAndCache = (endpoint) => {
const cachedData = cache.get(endpoint);
if (cachedData) {
return Promise.resolve(cachedData);
}
return fetch(`${BASE_URL}/${endpoint}`, {
  • A top-level container renders the rest of the component tree.
  • That container holds child presentational components, as well as other containers which in turn hold presentational components.
  • Containers are responsible for getting data from state and updating internal state in response to user interaction.
  • Presentational components are responsible for receiving data from their parents to display and alerting their parents when a user-triggered change needs to be made via the DDAU pattern
  • Reducers are just pure functions that take the previous state and an action, and return the next state. ( https://redux.js.org/docs/introduction/ThreePrinciples.html ) ** Redux Three Principles **
  • The dispatch method is a method of the store object. An action is dispatched to trigger an update to the store.
  • react-redux and make a dumb and a smart component
const isMobile = window.innerWidth <= 376;
const isTablet = window.innerWidth <= 768;
const isDesktop = window.innerWidth <= 992;

Conditionally adding keys to JavaScript objects using spread operators and short-circuit evaluation

`const buildAnObjectFromAQuery = (query) => { const object = {}; if (query.foo) { object.foo = query.foo; } if (query.bar) { object.bar = query.bar; }