-
Code function relativeNumbers(a, b) { let m = Math.min(a, b)**(1/2) for (let i = 2; i <= m; i++) { //If A and B share a divisor if (a % i === 0 && b % i === 0) { return "non relative"; } } return "relative"; }
Test Cases const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold = 0; describe("relativeNumbers",()=>{ it("example tests", ()=>{ assert.deepEqual( relativeNumbers(8,9), "relative" ); }); });
Output:
-
Code - function relativeNumbers(a, b) {
let arrOne = [];let arrTwo = [];for (let i = 2; i < 10; i++) {if (a % i === 0 && a !== i) {arrOne.push(i);}if(b % i === 0 && b !== i){arrTwo.push(i)}}for(let i = 0; i < arrOne.length; i++){for(let j = 0; j < arrTwo.length; j++){if(arrOne[i] === arrTwo[j]){return "non relative"}else return "relative"- let m = Math.min(a, b)**(1/2)
- for (let i = 2; i <= m; i++) {
- //If A and B share a divisor
- if (a % i === 0 && b % i === 0) {
- return "non relative";
- }
- }
- return "relative";
- }
- 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 }}