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
export const SET_EXPRESSION = 'SET_EXPRESSION'; | |
export const CLEAR_EXPRESSION = 'CLEAR_EXPRESSION'; | |
export const DELETE_LAST_EXPRESSION_ENTRY = 'DELETE_LAST_EXPRESSION_ENTRY'; | |
export const EVALUATE_EXPRESSION = 'EVALUATE_EXPRESSION'; |
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
import * as types from '../types'; | |
import calculate from '../../utils/calculate' | |
let initialState = { | |
expression: '', | |
total: 0 | |
} | |
function setExpression({ expression, total}, action) { |
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
import { createStore, combineReducers } from 'redux'; | |
import calculateReducer from './reducers/calculateReducer' | |
const rootReducer = combineReducers({ | |
calculator: calculateReducer | |
}) | |
export default createStore( | |
rootReducer, | |
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() |
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
export default (expression) => { | |
const matched = (new RegExp('([\\d]+\\.?[\\d]*)?([-+/*][\\d]+\\.?[\\d]*)*')).exec(expression) | |
if (!matched) { | |
return 0; | |
} | |
if (/^[*+\/]/.test(expression)){ | |
return () => { |
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
import calculate from '../utils/calculate.js' | |
describe('Calculate', () => { | |
let expression; | |
it ('evaluates the expression correctly', () => { | |
expression = '2+3+4-4*3' | |
expect(calculate(expression)).toBe(-3); | |
expression = '0+3+4' | |
expect(calculate(expression)).toBe(7); |
NewerOlder