Files
freeCodeCamp/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/greatest-common-divisor.english.md
Randell Dawson 04f18e43f6 fix(curriculum): Remove unnecessary assert message argument from English Coding Interview Prep challenges - 02 (#36412)
* fix: removed assert msg argument

* fix: removed msgs surrounded by 2 single quotes

* fix: removed missing 2 assert msg arguments

* fix: remove msg surrounded by two single quotes

* fix: removed unnecessary assert msg args

* fix; remove msgs surrounded by double quotes

* fix: removed unnecessary assert msg args

* fix: remove unnecessary assert msg args

* fix: removed unnecessary assert msg arg

* fix: removed unnecessary assert msg args

* fix: removed unnecessary assert msg arg

* fix: removed unnecessary assert msg args

* fix: removed unnecessary assert msg args

* fix: removed unnecessary assert msg args

* fix: removed unnecessary assert msg args

* fix: removed unnecessary assert msg args

* fix: removed unnecessary assert msg arg

* fix: removed unnecessary assert msg args

* fix: Restore expected values to assertions

* fix: remove assertion message

Co-authored-by: Vivek Agrawal <vivekmittalagrawal@gmail.com>
2019-07-26 14:24:52 +02:00

1.4 KiB

title, id, challengeType
title id challengeType
Greatest common divisor 5a23c84252665b21eecc7e82 5

Description

Write a function that returns the greatest common divisor of two integers.

Instructions

Tests

tests:
  - text: <code>gcd</code> should be a function.
    testString: assert(typeof gcd=='function');
  - text: <code>gcd(24,36)</code> should return a number.
    testString: assert(typeof gcd(24,36)=='number');
  - text: <code>gcd(24,36)</code> should return <code>12</code>.
    testString: assert.equal(gcd(24,36),12);
  - text: <code>gcd(30,48)</code> should return <code>6</code>.
    testString: assert.equal(gcd(30,48),6);
  - text: <code>gcd(10,15)</code> should return <code>5</code>.
    testString: assert.equal(gcd(10,15),5);
  - text: <code>gcd(100,25)</code> should return <code>25</code>.
    testString: assert.equal(gcd(100,25),25);
  - text: <code>gcd(13,250)</code> should return <code>1</code>.
    testString: assert.equal(gcd(13,250),1);
  - text: <code>gcd(1300,250)</code> should return <code>50</code>.
    testString: assert.equal(gcd(1300,250),50);

Challenge Seed

function gcd(a, b) {
  // Good luck!
}

Solution

function gcd(a, b) {
  return b==0 ? Math.abs(a):gcd(b, a % b);
}