From Bulky Giraffe, 1 Year ago, written in Plain Text.
Embed
Hits: 74
1. function smallestCommons(arr) {
2.   arr = arr.sort((a, b) => a > b)
3.   let a = arr[0]
4.   let b = arr[1]
5.   let searchingInProgress = true
6.   let start = 1
7.   let next = 200
8.   let numbers = []
9.   let startIndex = a
10.   for (let i = 0 ; i < (b - a + 1) ; i++) {
11.     numbers.push([])
12.   }
13.
14.
15.   while (searchingInProgress) {
16.
17.     let multiplies = numbers.slice(0)
18.     //Creating 10x10 2D array of multiplies, each column represents a number in given range
19.     multiplies = multiplies.map( (number, index) => {
20.       let subMultiplies = []
21.       for (let i = start ; i < next ; i++) {
22.         subMultiplies.push((index + startIndex) * i)
23.       }
24.       return subMultiplies
25.     })
26.     //Searching through array of multiplies
27.     multiplies = multiplies.map( (multipliesSequence, index) => {
28.       //iterate through multiplies in sequence and returns only those which occur in every sequence
29.        return multipliesSequence.filter( multiply => {
31.          //checks if multiply exists in every column
32.          for (let i = 0 ; i < multiplies.length ; i++) {
34.                            multiplies[i].indexOf(multiply) !== -1
35.          }