Problem
- Write a function isDivisiblePixel that will tell you whether a wall of a certain length can exactly fit an integer number of pixels of a certain length.
- 특정 길이의 pixel 수(정수)가, 특정 길이의 벽에 정확히 부합할 수 있는지 확인한다.
Solution 01
function isDivisiblePixel(wallLength, pixelSize) {
if (wallLength % pixelSize === 0) {
return true;
} else {
return false;
}
}
isDivisiblePixel(1000, 1); // true
isDivisiblePixel(1000, 2); // true
isDivisiblePixel(1000, 3); // false
isDivisiblePixel(1000, 4); // true
isDivisiblePixel(1000, 5); // true
isDivisiblePixel(1000, 6); // false
Solution 02
function isDivisiblePixel(wallLength, pixelSize) {
return wallLength % pixelSize === 0 ? true : false;
}
isDivisiblePixel(1000, 1); // true
isDivisiblePixel(1000, 2); // true
isDivisiblePixel(1000, 3); // false
isDivisiblePixel(1000, 4); // true
isDivisiblePixel(1000, 5); // true
isDivisiblePixel(1000, 6); // false
Solution 03
function isDivisiblePixel(wallLength, pixelSize) {
return wallLength % pixelSize === 0;
}
isDivisiblePixel(1000, 1); // true
isDivisiblePixel(1000, 2); // true
isDivisiblePixel(1000, 3); // false
isDivisiblePixel(1000, 4); // true
isDivisiblePixel(1000, 5); // true
isDivisiblePixel(1000, 6); // false
Solution 04
function isDivisiblePixel(wallLength, pixelSize) {
return !(wallLength % pixelSize);
}
isDivisiblePixel(1000, 1); // true
isDivisiblePixel(1000, 2); // true
isDivisiblePixel(1000, 3); // false
isDivisiblePixel(1000, 4); // true
isDivisiblePixel(1000, 5); // true
isDivisiblePixel(1000, 6); // false