Skip to content

Instantly share code, notes, and snippets.

View lomse's full-sized avatar
😄
Working on a React Redux project

Sélom lomse

😄
Working on a React Redux project
View GitHub Profile
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 December 10, 2019 09:19
Degree of Array - Interview Question
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 = []
{
"compilerOptions": {
"outDir": "./dist/",
"jsx": "react",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"noUnusedLocals": true,
"noImplicitReturns": true,
@lomse
lomse / index.html
Created August 27, 2019 19:37
index.html for todos app with react hooks, typescript and redux
<!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 August 27, 2019 19:32
App.tsx file for todos app with react hooks, typescript and redux
import * as React from "react";
const App: React.FC = () => (
<div>Hello World!</div>
);
export default App;
@lomse
lomse / index.tsx
Created August 27, 2019 19:23
Index.tsx for todos app with react hooks, typescript and redux
import * as React from "react";
import { render } from "react-dom";
import App from "./components/App";
render(
<App />,
document.getElementById("root"),
);
@lomse
lomse / .babelrc
Created August 27, 2019 19:16
.babelrc for todos app with react hooks, typescript and redux
{
"presets": [
"@babel/preset-react",
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
@lomse
lomse / helper.test.js
Created October 20, 2018 18:38
helper.test.js file
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 }
/**
* addTodo
*
* @param {Array} list
* @param {Object} item
*/
export const addTodo = (list, item) => [item, ...list]
/**
* generateId
@lomse
lomse / TodoList.jsx
Created October 20, 2018 15:17
TodoList component
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 => {