Your two functions are identical.
const sum1 = function(list, prop){ return list.reduce( function(a, b){ return a + b[prop];}, 0);};
const sum2 = (list,prop) => { return list.reduce((a,b) => {return (a+ b[prop])}, 0)};
const list = [{foo:1},{foo:2},{foo:3}]
console.log(sum1(list, 'foo'));
console.log(sum2(list, 'foo'));
Answer from H.P. on Stack OverflowConvert normal function to arrow function - javascript
Convert function expression to arrow function.
Converting ECMAScript 6's arrow function to a regular function
How to convert a function to arrow function inside an object
Videos
An arrow function can usually be converted by replacing
(<args>) => <body>
with
function(<args>) { return <body>; }
So yours would be
rowCheckStatuses.reduce(function(a, b) { return a + b; }, 0)
There are exceptions to this rule so it's important that you read up on arrow functions if you want to know all of the differences. You should also note that arrow functions have a lexical this.
You can refactor it as:
if( rowCheckStatuses.reduce(function(a, b){return a + b}, 0)
The initial accumulator isn't necessary (unless you expect the array to be empty sometimes), it could be:
if( rowCheckStatuses.reduce(function(a, b){return a + b})
This number acts as a boolean to determine whether or not there is at least one "1" in the array
It might be faster (and clearer) to use:
if( rowCheckStatuses.some(function(a){return a == 1}))
which will return true if there are any 1s in rowCheckStatuses and will return as soon as one is encountered. Another alternative is indexOf:
if( rowCheckStatuses.indexOf(1) != -1)
Lots of alternatives.
You need no curly brackets, and no this for the console.
this.$scope.$watch(
() => this.$location.path(),
value => console.log(value)
);
There is no need to wrap location.path into another function. Also you could access console without this.
// no need to wrap single parameter like `(value)` for your tsLint config.
this.$scope.$watch(this.$location.path, value =>{
//this from parent
})
Your attempt was close, but you forgot to include the generic argument declaration in front of the arrow function parameters. Try something like this:
const log = <T>(message: T): IO<void> =>
new IO(() => console.log(message));
If you're working in a .tsx file, you may need to do something a little more complex to make it work.
You could try to use:
const log = <T>(message: T): IO<void> => new IO(() => console.log(message));