Examples:
sum of odd (0, 5) -> 0 + 3 + 5 -> 8
sum of odd (0, 9) -> 0 + 3 + 5 + 7 + 9 -> 24
sum of odd (5, 9) -> 5 + 7 + 9 -> 21
const sumOdd = (min, max) => (++max / 2 | 0) ** 2 - (min / 2 | 0) ** 2;
sumNechet = (a, b) => (b/2).toFixed()**2;- const sumOdd = (min, max) => (++max / 2 | 0) ** 2 - (min / 2 | 0) ** 2;
const chai = require("chai"); const assert = chai.assert; describe("sumOdd", function() { it("simple tests", function() { assert.strictEqual(sumOdd(0, 0), 0); assert.strictEqual(sumOdd(0, 1), 1); assert.strictEqual(sumOdd(0, 2), 1); assert.strictEqual(sumOdd(0, 3), 4); assert.strictEqual(sumOdd(0, 4), 4); assert.strictEqual(sumOdd(0, 5), 9); assert.strictEqual(sumOdd(0, 6), 9); assert.strictEqual(sumOdd(0, 7), 16); assert.strictEqual(sumOdd(0, 8), 16); assert.strictEqual(sumOdd(13, 15), 13 + 15); assert.strictEqual(sumOdd(14, 16), 15); assert.strictEqual(sumOdd(0, 15), 64); assert.strictEqual(sumOdd(5, 15), 60); assert.strictEqual(sumOdd(0, 17), 81); assert.strictEqual(sumOdd(3, 17), 80); assert.strictEqual(sumOdd(5, 17), 77); assert.strictEqual(sumOdd(25, 29), 81); }); });
// Since Node 10, we're using Mocha.// You can use `chai` for assertions.- const chai = require("chai");
- const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:// chai.config.truncateThreshold = 0;// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.// Uncomment the following to use the old assertions:// const Test = require("@codewars/test-compat");describe("Solution", function() {it("should test for something", function() {// Test.assertEquals(1 + 1, 2);assert.strictEqual(sumNechet(0,5),9);assert.strictEqual(sumNechet(0,15),64);- describe("sumOdd", function() {
- it("simple tests", function() {
- assert.strictEqual(sumOdd(0, 0), 0);
- assert.strictEqual(sumOdd(0, 1), 1);
- assert.strictEqual(sumOdd(0, 2), 1);
- assert.strictEqual(sumOdd(0, 3), 4);
- assert.strictEqual(sumOdd(0, 4), 4);
- assert.strictEqual(sumOdd(0, 5), 9);
- assert.strictEqual(sumOdd(0, 6), 9);
- assert.strictEqual(sumOdd(0, 7), 16);
- assert.strictEqual(sumOdd(0, 8), 16);
- assert.strictEqual(sumOdd(13, 15), 13 + 15);
- assert.strictEqual(sumOdd(14, 16), 15);
- assert.strictEqual(sumOdd(0, 15), 64);
- assert.strictEqual(sumOdd(5, 15), 60);
- assert.strictEqual(sumOdd(0, 17), 81);
- assert.strictEqual(sumOdd(3, 17), 80);
- assert.strictEqual(sumOdd(5, 17), 77);
- assert.strictEqual(sumOdd(25, 29), 81);
- });
- });