JavaScript - Determining Factors
Similar Tutorialsi am using trying to use the following code to find the prime factors of a number: Code: function prime(number){//returns prime factors of input in array test=2;//number to test divisibility factor_count=0//counts number of factors factors=[]; while (test<number){ quotiant=number/test quotiant_round=Math.floor(quotiant); if(quotiant==quotiant_round){//number is divisible by test factor_count=factor_count+1; factors[factor_count]=test; number=number/test; test=test-1;//counters adding one } test=test+1; } return (factors) } running it manually in chromes JavaScript console i get: prime(2)=[] prime(4)=[undefined, 2] prime(8)=[undefined, 2, 2] prime(6)=[undefined, 2] prime(9)=[undefined, 3] prime(27)=[undefined, 3, 3] prime(18)=[undefined, 2, 3] i am using the = to separator my input from its output I need some help putting the factors of a number (y) into an array For example if y = 20: [1, 2, 4, 5, 10, 20] Once I have this, I can use it to factor a quadratic: (ax = c)(bx = d) if c = 3 and d = 5 then I could check if 1c was a decimal, if 20d was a decimal and then vice versa Basically, I can use these numbers to see if b or d is a whole number and if it isn't, try the next one. If none of them are, then I can do y(ax + c)(bx + d) Thanks! Basically I want to factor a number and select the two closest numbers to the middle of the factors for example: 20 factors to 1, 2, 4, 5, 10, 20 I want it to return 4 and 5 If the number is has an odd number of factors (has to be a perfect square) I want it to select the middle number and say it twice for example: 64 factors to 1, 2, 4, 8, 16, 32, 64 I want it to return 8 and 8 Would I use an array or what? My code should probably look like: PHP Code: x = //Factors array y = //number of items in x if (/*y is even*/){ i = y/2 i2 = i+1 a = [i] b = [i2] } else{ i = //somehow the center number? i2 = i a = [i] b = [i2] } Hello All, I am a JS newbie and I'm wondering if there a way to figure out the sentence from which a word has been highlighted. Essentially, when a user selects a word or a phrase, I should output the sentence from which it's been selected. Is this possible with JS or with any server side languages? - Pallav Some background might better help my actual problem. Feel free to address either with any relevant insights. While attempting to create a greasemonkey script in FF2 (don't ask), I discovered that the "let" statement was causing my code to fail. After confirming that this statement has been available since FF2 (js engine 1.7) https://developer.mozilla.org/en/New_in_JavaScript_1.7, I became curious as one determines their javascript engine in FF. IE has a way to inspect the jscript engine, ala http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx , but I couldn't find anything similar for FF. Feel free to list links for testing engines in other browsers, too. I can't use irc at work, so it's good to know this place is still around for numb-nuts like me. :-) Many, many thanks (in-advance). Hi All, I have HTML table with couple of columns with combobox in each row.when I select value in any of the combobox, I want to determine the column number of the combobox which is clicked.Is there any function which can be used to do this?Please help. Thanks, Anil |