Skip to content

Instantly share code, notes, and snippets.

Avatar
😄
Working on a React Redux project

Sélom Amouzou lomse

😄
Working on a React Redux project
View GitHub Profile
View maxchar-algorithm-solution.js
function maxChar(str) {
const arr = str.split("");
// map letters to total number of occurences
const map = arr.reduce((acc, letter) => {
if (letter.trim()) {
acc.set(letter, (acc.get(letter) || 0) + 1)
}
return acc;
@lomse
lomse / degree-of-array.js
Last active Dec 10, 2019
Degree of Array - Interview Question
View degree-of-array.js
function findShortestSubArray(nums) {
// Elements is a map of key => elementInfo
// with key being each of the elements in the array
// and elementInfo being the object with properties count, leftIndex, rightIndex for
// one particular element in the array
let degree = 0
const elementsInfoHighestCount = new Map()
let subArray = []
View tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"jsx": "react",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"noUnusedLocals": true,
"noImplicitReturns": true,
@lomse
lomse / index.html
Created Aug 27, 2019
index.html for todos app with react hooks, typescript and redux
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>React Hooks + Redux + Typescript</title></head>
<body>
<div id="root"></div>
<script src="./src/index.tsx"></script>
@lomse
lomse / App.tsx
Created Aug 27, 2019
App.tsx file for todos app with react hooks, typescript and redux
View App.tsx
import * as React from "react";
const App: React.FC = () => (
<div>Hello World!</div>
);
export default App;
@lomse
lomse / index.tsx
Created Aug 27, 2019
Index.tsx for todos app with react hooks, typescript and redux
View index.tsx
import * as React from "react";
import { render } from "react-dom";
import App from "./components/App";
render(
<App />,
document.getElementById("root"),
);
@lomse
lomse / .babelrc
Created Aug 27, 2019
.babelrc for todos app with react hooks, typescript and redux
View .babelrc
{
"presets": [
"@babel/preset-react",
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
@lomse
lomse / helper.test.js
Created Oct 20, 2018
helper.test.js file
View helper.test.js
import { addTodo } from './helper'
describe('addTodo', () => {
it('should add todo to the list', () => {
const startTodos = [
{ id: 1, name: 'one', isComplete: false },
{ id: 2, name: 'two', isComplete: false }
]
const newTodo = { id: 3, name: 'three', isComplete: false }
View helper.js
/**
* addTodo
*
* @param {Array} list
* @param {Object} item
*/
export const addTodo = (list, item) => [item, ...list]
/**
* generateId
@lomse
lomse / TodoList.jsx
Created Oct 20, 2018
TodoList component
View TodoList.jsx
import React from "react"
import styled from "styled-components"
import PropTypes from "prop-types"
import TodoItem from "./TodoItem"
const StyledUl = styled.ul`
padding: 0;
`
const TodoList = props => {