Skip to content

Instantly share code, notes, and snippets.

@guilhermegregio
Created June 22, 2017 13:17
Show Gist options
  • Save guilhermegregio/f46d3f680d87e57795710a38db748b4b to your computer and use it in GitHub Desktop.
Save guilhermegregio/f46d3f680d87e57795710a38db748b4b to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/rodimum
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://npmcdn.com/expect/umd/expect.min.js"></script>
</head>
<body>
<script id="jsbin-javascript">
'use strict';
var toTotalBarLbs = function toTotalBarLbs(weigth) {
return (45 + weigth * 2) * 10;
};
var toKg = function toKg(lbs) {
return lbs * 0.453592;
};
var sum = function sum(x, y) {
return Math.round(x + y);
};
var singleWeigthLbs = [10, 20, 20, 20, 30, 30, 40, 40, 50, 60];
var weigthKg = singleWeigthLbs.map(toTotalBarLbs).map(toKg).reduce(sum);
//console.assert(weigthKg === 4944, 'Valor não esta correto')
expect(weigthKg).toBe(4944);
console.log('Passou');
</script>
<script id="jsbin-source-javascript" type="text/javascript">const toTotalBarLbs = weigth=>(45+weigth*2)*10
const toKg = lbs=> lbs * 0.453592
const sum = (x,y)=>Math.round(x+y)
const singleWeigthLbs = [10,20,20,20,30,30,40,40,50,60]
const weigthKg = singleWeigthLbs
.map(toTotalBarLbs)
.map(toKg)
.reduce(sum)
//console.assert(weigthKg === 4944, 'Valor não esta correto')
expect(weigthKg).toBe(4944);
console.log('Passou')</script></body>
</html>
'use strict';
var toTotalBarLbs = function toTotalBarLbs(weigth) {
return (45 + weigth * 2) * 10;
};
var toKg = function toKg(lbs) {
return lbs * 0.453592;
};
var sum = function sum(x, y) {
return Math.round(x + y);
};
var singleWeigthLbs = [10, 20, 20, 20, 30, 30, 40, 40, 50, 60];
var weigthKg = singleWeigthLbs.map(toTotalBarLbs).map(toKg).reduce(sum);
//console.assert(weigthKg === 4944, 'Valor não esta correto')
expect(weigthKg).toBe(4944);
console.log('Passou');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment