gruss kyros,
Ich möchte gern in ein Array
eine Zahlenreihe durch eine
Schleife füllen lassen.
Geht das?
die anderen antwortenden ergaenzend, moechte
ich ein von »Smalltalk«s kontrollstrukturen
inspiriertes beispiel bringen.
Smalltalks
aNumber to: aNumber do: [ :i | anOperation ].
liesse sich in JavaScript z.b. als
[link:https://github.com/petsel/javascript-api-extensions/blob/master/core/smalltalk-inspired-control-structures/Number.to.each.js@title=[Number\].to([Number\]).each([Function\]);]
implementieren.
die von Dir angefragte loesung saehe dann
so aus:
/*
beispiel auf [link:http://jconsole.com/@title=jconsole.com] oder
auf die JavaScript-konsole des
browsers loslassen.
*/
(function(){var e=this,j=e.Number,k=j.prototype,l=e.String.prototype,m=function(g){return function(b,d,a,c){if(typeof a=="function"){c=c||(typeof c=="undefined"||typeof c=="object"?null:c);var h=-1,f,i;if(b<=d){f=b-1;for(i=d-f;++h<i;)a.call(c,h,i,a,++f,b,d)}else{f=b+1;for(i=g(d-f);++h<i;)a.call(c,h,i,a,--f,b,d)}}}}(e.Math.abs),n=function(g,b,d){return function(a){a=g(a);return a=b(a)?d(a):-1}}(j,e.isFinite,e.Math.floor),o=function(g,b,d){return function(a,c){initialValue=d.call(a).valueOf();a=b(a);c=b(c);this.valueOf=function(){return initialValue};this.toString=function(){return""+initialValue};this.each=function(h,f){g(a,c,h,f);return initialValue}}}(m,n,e.Object.prototype.valueOf);k.to=l.to=function(g){return function(b){return new g(this,b)}}(o);o=n=m=l=k=j=e=null;delete o;delete n;delete m;delete l;delete k;delete j;delete e;delete arguments.callee}).call(null);
var chars = [];
(100).to(65).each(function (idx, len, fct, count, from, to) {
chars[idx] = count;
//chars.push(count);
});
chars;
so long - peterS. - pseliger@gmx.net
--
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]