Solving Popular Algorithms: Self Dividing Numbers

Too true, Gordon.
[1,2,3,4,5,6,7,8,9,11,12,15,22]
selfDividingNumbers = (left, right) => {
let allNums = []

for (let i = left; i <= right; i++) {
allNums.push(i)
}
}
selfDividingNumbers = (left, right) => {
//step one: creating an array of all possible numbers
let allNums = []

for (let i = left; i <= right; i++) {
allNums.push(i)
}
//step two: creating an object of all possible numbers
//plus their digits
let numsObj = {}

for (let j = 0; j < allNums.length; j++) {
numsObj[allNums[j]] = allNums[j].toString().split("")
}
}
selfDividingNumbers = (left, right) => {
//step one: creating an array of all possible numbers
let allNums = []

for (let i = left; i <= right; i++) {
allNums.push(i)
}
//step two: creating an object of all possible numbers
//plus their digits
let numsObj = {}

for (let j = 0; j < allNums.length; j++) {
numsObj[allNums[j]] = allNums[j].toString().split("")
}

//step three: looping through our objects keys and values
//to find what numbers are self dividing
for (let num in numsObj) {
for (let char of numsObj[num] {
if (parseInt(num) % parseInt(char) !== 0) {
delete numsObj[num]
}
}
}
}
selfDividingNumbers = (left, right) => {
//step one: creating an array of all possible numbers
let allNums = []

for (let i = left; i <= right; i++) {
allNums.push(i)
}
//step two: creating an object of all possible numbers
//plus their digits
let numsObj = {}

for (let j = 0; j < allNums.length; j++) {
numsObj[allNums[j]] = allNums[j].toString().split("")
}

//step three: looping through our objects keys and values
//to find what numbers are self dividing
for (let num in numsObj) {
for (let char of numsObj[num] {
if (parseInt(num) % parseInt(char) !== 0) {
delete numsObj[num]
}
}
}

//NEVER FORGET TO RETURN!!!
return Object.keys(numsObj).map(num => parseInt(num))
}
You, attempting to find a better solution to this problem

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

React Hook : it only works in functional component.there

Lessons I learned while learning React

Core Foundation — Arrays With non-CF Objects

Calling JavaScript code from C/C++ using WebAssembly

Making API Calls with React

Voices from the Community v2019

How to get setup with React DnD

Task 7.2 — USE CASE OF JAVA SCRIPT

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
HopeGiometti

HopeGiometti

More from Medium

Programming a Queue with a Doubly Linked List

What is the Huffman Algorithm

ARRAYS AND STRINGS DATA STRUCTURES.

Linking Together Linked Lists