Factors of an integer: Difference between revisions

m
→‎{{header|R}}: Syntax highlighting.
(Moved Polyglot:PL/I and PL/M into the correct place)
m (→‎{{header|R}}: Syntax highlighting.)
Line 5,379:
=={{header|R}}==
===Array solution===
<lang Rrsplus>factors <- function(n)
{
if(length(n) > 1)
Line 5,404:
===Filter solution===
With identical output, a more idiomatic way is to use R's Filter.
<lang Rrsplus>factors <- function(n) c(Filter(function(x) n %% x == 0, seq_len(n %/% 2)), n)
#Vectorize is an interesting alternative to the previous solution's lapply.
manyFactors <- function(vec) Vectorize(factors)(vec)</lang>
331

edits