vinnizworld
10/8/2016 - 4:49 AM

Fixed Point Number 9 as explained by vSouce https://www.youtube.com/watch?v=csInNn6pfT4

Fixed Point Number 9 as explained by vSouce https://www.youtube.com/watch?v=csInNn6pfT4

function fp(num)
{
	// Typecast the user input
	num = parseInt(num) || 0;

	// Don't accept if length is 1
	if( num < 10 ){
		throw new Error('You must pass a number of at least two digits');
	}

	// Add it's digits
	while(num > 9) {
		let sum = (num + '').split('').map(parseFloat).reduce( (a,b) => a + b );
		console.log('%d - %d => %d', num, sum, num - sum);
		num = num - sum;
	}

	return num;
}