- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

A proper fraction is the one that exists in the p/q form (both p and q being natural numbers)

Suppose we divide the numerator of a fraction (say a) with its denominator (say b), to get quotient q and remainder r.

The mixed fraction form for fraction (a/b) will be −

qrb

And it is pronounced as "q wholes and r by b”.

We are required to write a JavaScript function that takes in an array of exactly two numbers representing a proper fraction and our function should return an array with three numbers representing its mixed form

Following is the code −

const arr = [43, 13]; const properToMixed = arr => { const quotient = Math.floor(arr[0] / arr[1]); const remainder = arr[0] % arr[1]; if(remainder === 0){ return [quotient]; }else{ return [quotient, remainder, arr[1]]; }; }; console.log(properToMixed(arr));

Following is the output in the console −

[ 3, 4, 13 ]

- Related Questions & Answers
- C program to convert decimal fraction to binary fraction
- Fraction module in Python
- Fraction to Recurring Decimal in C++
- Convert decimal fraction to binary number in C++
- How to display fraction in base R plot?
- K-th Smallest Prime Fraction in C++
- Reduce the fraction to its lowest form in C++
- as_integer_ratio() in Python for reduced fraction of a given rational
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d) in C++
- C++ program to find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- How to display fraction in a plot title using ggplot2 in R?
- Maximum rational number (or fraction) from an array in C++
- Write a C program to reduce any fraction to least terms using while loop
- Program to count number of fraction pairs whose sum is 1 in python
- Signals and Systems – Partial Fraction Expansion Method for Inverse Z-Transform

Advertisements