Skip to content

Instantly share code, notes, and snippets.

@jgierer12
Created May 4, 2017 20:37
Show Gist options
  • Save jgierer12/3ed2e7da8fc6e95590a86d20a907b6b4 to your computer and use it in GitHub Desktop.
Save jgierer12/3ed2e7da8fc6e95590a86d20a907b6b4 to your computer and use it in GitHub Desktop.
const gcd = (x, y) => y ? gcd(y, x % y) : x;
const simplify = xs => xs.map(x => x / gcd(...xs));
export default str => simplify(str.split(' ')).join(' ');
import m from '.';
test('4 8 -> 1 2', () => {
expect(m('4 8')).toBe('1 2');
});
test('1536 78360 -> 64 3265', () => {
expect(m('1536 78360')).toBe('64 3265');
});
test('51478 5536 -> 25739 2768', () => {
expect(m('51478 5536')).toBe('25739 2768');
});
test('46410 119340 -> 7 18', () => {
expect(m('46410 119340')).toBe('7 18');
});
test('7673 4729 -> 7673 4729', () => {
expect(m('7673 4729')).toBe('7673 4729');
});
test('4096 1024 -> 4 1', () => {
expect(m('4096 1024')).toBe('4 1');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment