Contact: aviboots(AT)netvision.net.il
41,214 questions
53,716 answers
573 users
function next_multiple_of_4(num) { return (num % 4 === 0) ? num + 4 : (num + 3) & ~0x03; } let nums = [25, 20, 0, -9]; nums.forEach(num => { console.log(next_multiple_of_4(num)); }); /* run: 28 24 4 -8 */
function next_multiple_of_4(num) { return num + (4 - num % 4) } let nums = [25, 20, 0, -9]; nums.forEach(num => { console.log(next_multiple_of_4(num)); }); /* run: 28 24 4 -4 */