peterjaric / mathemancy.js

one.plus.two.times.five
5 stars 4 forks source link

Simpler but dumber? #1

Closed karlpokus closed 7 years ago

karlpokus commented 7 years ago

This is fun! I made a simpler implementation that works for both single-, and multiple digits and the four common operators. Although you have to pass the string to a function though (and that is hard stuff).

function epicMath(str) {
  var wordMap = {one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, plus: '+', minus: '-', times: '*', dividedBy: '/'};
  var mappedString = str.split('.').map(function(item){return wordMap[item]}).join('');
  return eval(mappedString);
}
// works with 'six.one.five.plus.two' and 'four.five.six.times.three.dividedby.five'
peterjaric commented 7 years ago

The current implementation actually supports this already! :) I tried your examples now, just to be sure, and they worked (after changing the dividedby to dividedBy). Also, the warping of the property access notation was kind of the point of my take on this.

So, I'll close the PR, but thanks for giving some attention to this silly project!

karlpokus commented 7 years ago

the warping of the property access notation

Lots of words. Awesome!