Often I study some JavaScript
interview questions, suddenly I saw a question about usage of reduce
function for sorting an Array
, I read about it in MDN and the usage of it in some medium
articles, But sorting an Array
is so Innovative:
const arr = [91,4,6,24,8,7,59,3,13,0,11,98,54,23,52,87,4];
I thought a lot, but I've no idea about how answer this question, how must be the reduce
call back
function? what is the initialValue
of reduce
function? And what are the accumulator
and currentValue
of call back
function of reduce
?
And at the end, does this way have some benefits than other sorting algorithms? Or Is it useful to improve other algorithms?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…