DEV Community

loading...

Discussion on: Project Euler #5 - Finding the Smallest Multiple

Collapse
karataev profile image
Eugene Karataev

Bruteforce node solution 🤣

const assert = require('assert');

console.clear();

function findSmallestMultiple(numbers) {
  function isDividable(num) {
    for (let i = numbers.length - 1; i >= 0; i--) {
      if (num % numbers[i] !== 0) return false;
    }
    return true;
  }

  let counter = 1;
  while (true) {
    if (isDividable(counter)) break;
    counter++;
  }
  return counter;
}

// assert(findSmallestMultiple([7,8,9,10]) === 2520);

console.log(findSmallestMultiple([11,12,13,14,15,16,17,18,19,20]));
Collapse
crownedprinz profile image
Ademola John

Please how do i put my code in this snippet like you did when i want to comment with my own answer

Collapse
karataev profile image
Eugene Karataev

Wrap your content with three backtics to render it as a code snippet.

code snippet

const yourCode = 'here';
Thread Thread
crownedprinz profile image
Ademola John

Thannk you so much Eugene. This gave me tough time