Saturday, May 31, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

Find next higher natural number that is divisble by another number

Published: February 11, 2022Last updated: February 11, 2022

Write a function that takes two numbers, say x and y, as arguments. We need to check if x is divisible by y. If yes, then return x. If not, return the next higher natural number that is divisible by y.

const findDivisble = (x, y) => {
   if (x % y === 0) return x;

   if(y < 0) return 0;

   const divisor = parseInt(x / y);
   return divisor * y + y;
}

console.log(findDivisble(7, 3)); // 9

You May Also Like

Failed form propType: You provided a `value` prop to a form field without an `onChange` handler

September 2, 2019 beroza

Observer Design Pattern

September 15, 2024 beroza

List.of() vs Collections.emptyList() which one is better?

July 24, 2020 beroza

Use cases of Sets in JavaScript

September 19, 2021 beroza

How to render image with srcset and sizes in WordPress?

June 1, 2021 beroza

Why LinkedList is important?

December 25, 2022 beroza

Uncaught TypeError: object is not iterable (cannot read property Symbol (Symbol.iterator))

May 10, 2019 beroza

String.equals vs == operator in Java

November 13, 2019 beroza

How to solve “Add Expires headers” of GTMatrix for websites?

January 5, 2020 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Languages

  • EnglishEnglish
  • বাংলাবাংলা

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.