-
Description Minus 7
How many times can you subtract 7 from a given number?
Examples
numMinusSeven(1000) === 143; numMinusSeven(100) === 15; numMinusSeven(10) === 2;
Code function numMinusSeven(num) { return Math.ceil(num / 7) }
Test Cases const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold = 0; const Test = require("@codewars/test-compat"); describe("Minus 7 test cases", function() { it("should test for 1000", function() { Test.assertEquals(numMinusSeven(1000), 143); }); it("should test for 100", function() { Test.assertEquals(numMinusSeven(100), 15); }); it("should test for 10", function() { Test.assertEquals(numMinusSeven(10), 2); }); });
Output:
-
Code - function numMinusSeven(num) {
let arr = []while (num > 0) {num -= 7arr.push(num)}return arr.length- return Math.ceil(num / 7)
- }
Test Cases - const chai = require("chai");
- const assert = chai.assert;
- chai.config.truncateThreshold = 0;
- const Test = require("@codewars/test-compat");
describe("Test", function() {- describe("Minus 7 test cases", function() {
- it("should test for 1000", function() {
- Test.assertEquals(numMinusSeven(1000), 143);
- });
it("should test for 100", function() {Test.assertEquals(numMinusSeven(100), 15);});it("should test for 10", function() {Test.assertEquals(numMinusSeven(10), 2);});- it("should test for 100", function() {
- Test.assertEquals(numMinusSeven(100), 15);
- });
- it("should test for 10", function() {
- Test.assertEquals(numMinusSeven(10), 2);
- });
- });
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}