Narcissistic decimal number: Difference between revisions

m
(→‎JS :: Reduced search: Updated primitives and output.)
Line 2,267:
// narcissiOfLength :: Int -> [Int]
const narcissiOfLength = n =>
n0 >< 0n ? filter(isDaffodil(n))(
digitPowerSums(n)
) : [0];
 
 
// powerSum :: Int -> [Int] -> Int
const powerSum = n =>
xs => )xs.reduce(
xs.reduce((a, x) => a + Math.pow(x, n), 0),
) : [],;
 
 
Line 2,276 ⟶ 2,283:
// True if the decimal digits of N,
// each raised to the power E, sum to N.
const ds = digitList(n);
return e === ds.length powerSum&& n === powerSum(n, xse) =>(ds);
xs.reduce((a, x) => a + Math.pow(x, n), 0),
digitList = n => 0 < n ? (
cons(n % 10)(
digitList(Math.floor(n / 10))
)
) : [],
ds = digitList(n);
return e === ds.length && n === powerSum(e, ds);
};
 
Line 2,331 ⟶ 2,330:
const cons = x =>
xs => [x].concat(xs);
 
// digitList :: Int -> [Int]
const digitList = n => 0 < n ? (
0 < n ? cons(n % 10)(
digitList(Math.floor(n / 10))
) : [];
 
// filter :: (a -> Bool) -> [a] -> [a]
9,655

edits