Source:
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_360/https://nicolas-hoizey.com/2003/10/gasteroprod_v1.png 360w,
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_670/https://nicolas-hoizey.com/2003/10/gasteroprod_v1.png 670w,
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_980/https://nicolas-hoizey.com/2003/10/gasteroprod_v1.png 980w,
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_1024/https://nicolas-hoizey.com/2003/10/gasteroprod_v1.png 1024w
Expected result:
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_1024/https://nicolas-hoizey.com/2003/10/gasteroprod_v1.png
Source:
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_360/https://nicolas-hoizey.com/2002/10/doc-136.png 360w,
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_1024/https://nicolas-hoizey.com/2002/10/doc-136.png 1024w,
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_670/https://nicolas-hoizey.com/2002/10/doc-136.png 670w,
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_980/https://nicolas-hoizey.com/2002/10/doc-136.png 980w
Expected result:
https://res.cloudinary.com/nho/image/fetch/c_limit,f_auto,q_auto,w_1024/https://nicolas-hoizey.com/2002/10/doc-136.png
Source:
https://example.com/some-small-image.jpg 320w, https://example.com/some-larger-image.jpg 640w, https://example.com/some-huge-image.jpg 2000w, https://example.com/some-large-image.jpg 980w
Expected result:
https://example.com/some-huge-image.jpg
@nhoizey v'là la bonne version :
Explications :
\S+
.x: y
dans un contexte de hash équivaut à:x => y
.inject
(nom "rubyesque" dereduce
, qui en est l'alias), il prendra le premier élément comme accumulateur et démarrera l'itération au second, ce qui nous va parfaitement (idem en JS)cur
etnew
, sémantiquement ; en plus,new
est mal vu comme identifiant car c'est normalement réservé à l'opérateur d'instantiation des classes (ex.Person.new
)reduce
doit toujours renvoyer l'accumulateur, même s'il n'a pas changé. C'est là où tu foirais ; le fait de réaffectercur
n'avait d'ailleurs aucun intérêt (référence bloc-locale), ce qui compte c'est la valeur de retour du bloc, donc de sa dernière expression évaluée, ici l'affectation (coup de bol dans un cas de série croissante)Voilou…