Search Results

Search found 3602 results on 145 pages for 'jagged arrays'.

Page 21/145 | < Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >

  • Arrays in JavaScript

    - by caramel1991
    While reading a book about JavaScript I stumbled across an example: var names = new Array("Paul","Catherine","Steve"); var ages = new Array(31,29,34); var concatArray; concatArray = names.concat(ages); My question is, why doesn't the variable concatArray need to be define as a new Array() in order to store the concatenated data for both arrays name and ages , but when I try to treat the concatArray as an array by adding another line of code "document.write(concatArray[0])", it works just like an array and shows me the data stored in the first element. I just wonder why I'm not declaring the concatArray as a new array, yet it still works as one.

    Read the article

  • using KVO to filter an NSTableView using NSPredicate (with arrays)

    - by KingRufus
    My UI is not updating when I expect it to. The application displays "projects" using a view similar to iTunes -- a source list on the left lets you filter a list (NSTableView) on the right. My filters update properly when they are examining any simple field (like name, a string), but not for arrays (like tags). I'm removing a tag from one of my objects (from an NSMutableArray field called "tags") and I expect it to disappear from the list because it no longer matches the predicate that is bound to my table's NSArrayController. ProjectBrowser.mm: self.filter = NSPredicate* srcPredicate = [NSPredicate predicateWithFormat:@"%@ IN %K", selectedTag, @"tags"]; Project.mm: [self willChangeValueForKey:@"tags"]; [tags removeAllObjects]; [self didChangeValueForKey:@"tags"]; I've also tried this, but the result is the same: [[self mutableArrayValueForKey:@"tags"] removeAllObjects]; Interface Builder setup: a ProjectBrowser object is the XIB's File Owner an NSArrayController (Project Controller) has its Content Array bound to "File's Owner".projects Project Controller's filter predicate is bound to "File's Owner".filter NSTableView's column is bound to "Project Controller".name

    Read the article

  • How do Arrays work in C#?

    - by Slateboard
    I know that they are used to store data, but I have a difficult time understanding exactly how to use them in a program. In addition, I found this site with a tetris clone tutorial (the actual tutorial is missing). It uses arrays, but I can't really make sense of how it works. Here's an example of the code - public int[, ,] TShape = new int[4, 4, 2] { {{1, 0}, {0, 1}, {1, 1}, {2, 1}}, {{1, 0}, {0, 1}, {1, 1}, {1, 2}}, {{0, 0}, {1, 0}, {2, 0}, {1, 1}}, {{0, 0}, {0, 1}, {1, 1}, {0, 2}}}; Could it be that I'm looking too hard into this, or perhaps there's something I'm not grasping about it?

    Read the article

  • Array.Copy: strange exception while concatenating two byte arrays

    - by robob
    In a application of mine that is developed in C# I have the following code: byte[] resb = new byte[Buffer.ByteLength(blockAr) + Buffer.ByteLength(previous)]; Array.Copy(blockAr, 0, resb,0, blockAr.Length); Array.Copy(previous, 0, resb, blockAr.Length, previous.Length); It's a very simple code to concatenate two byte arrays. The problem is that in some particular situation that I don't know I have that exception: ArgumentOutOfRangeException: sourceIndex is less than the lower bound of the first dimension of sourceArray. I cannot see any of strange in my code and I am not able to reproduce the exception. Could anyone help me to identify the problem? thanks

    Read the article

  • How to split strings at specific intervals to arrays in javascript

    - by t3st
    how to split strings at specific interveals to arrays in javascript for example: split this string into 4 characters (including space and characters) this is an example should be split,numbers(123),space,characters also included to this ------> 1st array is ------> 2nd array an ------> 3rd array exam ------> 4th array ple ------> 5th array shou ------> 6th array ............ etc till..... ..ed ------> last array

    Read the article

  • Form Arrays support across browsers

    - by Stomped
    I'm not even sure if form arrays is the proper term, but it looks a bit like this: <input name='element[]' type='text' /> <input name='element[]' type='text' /> Which is then retrieved in PHP as an array stored in $_POST['element'] -- in this case with 2 values. I've tested it in the browsers I have available to me, but I've never seen this before and I'm wondering is this supported pretty much in all browsers? Or is this something very old that I've just not run into? Thanks!

    Read the article

  • How to insert many rows of data from arrays/lists to SQL Server (DataSet, DataTable)

    - by Kamil
    I need little help with transferring data from variables, arrays, lists to my SQL Server. Im not bad in SQL, but im not familiar with DataSet, DataTable objects. My data is now stored in list of strings (List). Every string in that list looks similar to this: QWERTY,19920604,0.91,0.35,0.34,0.35,343840 There are about 900000 rows like this. Target datatypes in SQL Server: BIGINT (primary key, im not inserting it, its identity(1,1)) VARCHAR(10), DATE, DECIMAL(10,2), DECIMAL(10,2), DECIMAL(10,2), DECIMAL(10,2), INT How to convert that data to SQL Server data types? How to insert that data into SQL Server? Also i need some progress bar updates between inserts. I could do this using old-fashion SQL command, but i have learn more modern way :)

    Read the article

  • A way of allocating multidimensional arrays dynamically

    - by C77431
    salute.. I am learning dynamic allocations for multidimensional arrays in a book and I found some ways for that, And now haven't problem in it. But the author of the book shows us a way, but it doesn't work correctly. It is this: pbeans = new double [3][4]; // Allocate memory for a 3x4 array And this is the error: error C2440: '=' : cannot convert from 'int (*)[4]' to 'int *' how should i define pbeans ( if this type of coding is legal)? and what is the problem exactly? Regards.

    Read the article

  • C++ Array of Variable sized Arrays

    - by adam
    I am very new to C++ and I realise the following is not necessarily as easy as I'd like it to be, but I'd really appreciate a more expert opinion. I am essentially trying to achieve a dynamic iteration over a variable sized array of variable sized arrays similar to the following. String *2d_array[][] = {{"A1","A2"},{"B1","B2","B3"},{"C1"}}; for (int i=0; i<2d_array.length; i++) { for (int j=0; j<2d_array[i].length; j++) { print(2d_array[i][j]); } } Is there a reasonable way to do this? Perhaps by using a vector, or another struct? Thanks :)

    Read the article

  • Find a common element within N arrays

    - by kunjaan
    If I have N arrays, what is the best(Time complexity. Space is not important) way to find the common elements. You could just find 1 element and stop. Edit: The elements are all Numbers. Edit: These are unsorted. Please do not sort and scan. This is not a homework problem. Somebody asked me this question a long time ago. He was using a hash to solve the problem. I was thinking if SO has solved similar problems.

    Read the article

  • Building an array of arrays

    - by iFloh
    I am trying to get the following loop working to fill an array of arrays: while (condition) { [itemsArray fillFromDB]; if (! [checkArray containsObject:checkFlag]) { // Add existing itemsArray to myArray if (itemsArray.count) { // add the itemsArray to myArray and create a new instance of itemsArray [myArray addObject:itemsArray]; [itemsArray release]; NSMutableArray *itemsArray = [[NSMutableArray alloc] init]; } [itemsArray addObject:myObject]; [checkArray addObject:checkFlag]; } else { [itemsArray addObject:tmpEvent]; } } However I try to shape this loop it falls over the release of itemsArray when I use release (as above), the array does not re-initialise as a new instance with alloc. Whilst expecting emptyness, the next Object is added to the old array. when I use removeAllObjects, my Array is emptied and so is the array attached to myArray. Where am I going in the wrong direction?

    Read the article

  • Correct way to clear/release an array of arrays

    - by iFloh
    And again my array of arrays .... When I have an array "x" that contains multiple instances of an array "y", how do I clear/release it without risking memory leaks? are the following calls sufficient? (a) clearing the array [x removeAllObjects]; (b) releasing the array [x release]; or do I need to enumerate the array, such as: (c) clearing the array for(int i=0;i<x.count;i++) [[x objectAtIndex:i] release]; [x removeAllObjects]; (d) releasing the array for(int i=0;i<x.count;i++) [[x objectAtIndex:i] release]; [x release]; thanks in advance

    Read the article

  • unit testing methods with arrays as argument

    - by Ryan
    I am porting over some C++ assembly to VB that performs demodulation of various waveforms. I decided to go the unit test route instead of building a test app to get a feel for how testing is performed. The original demodulation code accepts an array that is the waveform along with some other arguments. How should one go about performing a test on something that has an array as an argument? Is it acceptable to generate fake data in a file and read it in at the beginning of the test? On a side note - The original C++ code was written because we were performing math that we couldn't do in VB6 so we had to cross boundaries between C++ and VB6 and arrays were used. Is there a "better" way of handling large amounts of data in the .NET world that us VB6 programmers may not yet be privy to? Or if we aren't crossing that managed/un-managed boundary, should we be representing our data as objects instead? Thanks all!

    Read the article

  • Ternary operator or chosing from two arrays with the boolean as index

    - by ajax333221
    Which of these lines is more understandable, faster jsPerf, easier to maintain?: arr = bol ? [[-2,1],[-1,2]] : [[-1,0],[-1,1]]; //or arr = [[[-1,0],[-1,1]], [[-2,1],[-1,2]]][bol*1]; I usually write code for computers (not for humans), but this is starting to be a problem when I am not the only one maintaining the code and work for a team. I am unsure, the first example looks neat but are two different arrays, and the second is a single array and seem to transmit what is being done easier. I also considered using an if-else, but I don't like the idea of writing two arr = .... Or are there better options? I need serious guidance, I have never worried about others seeing my code.

    Read the article

  • Nesting arrays into NSDictionary object (Objective-C)

    - by antalbud
    I would like to define tasks using NSDictionary, which I'd like to save in a plist file (I didn't have much luck with Core Data so far), but got stuck at two points: -- When using initWithObjectsAndKeys: I can change the data type to number or boolean, using NSDate's numberWithInt: and numberWithBool: methods, respectively. I can't seem to find the method to change the type to date though. I couldn't find anything like that in the documentation. -- The second problem I ran into was with the nested arrays. How can I add them to the dictionary? I have uploaded a picture to here of what I am trying to achieve. Thank you in advance!

    Read the article

  • Arrays and application data

    - by s0mmer
    Hello everyone, At the moment i'm making an application where it is possible to make profiles with different settings. Which datatypes would you recommend me saving these information in? I have a table which is showing the profile name and the version number. But for each profile there need to be stored more information. Therefore the idea i'm working on have 2 arrays. 1 for all the profile information and 1 who is being made when loading the information. The second array is the one going to be showed in the table. Because the table doesnt show all the stored information. .. but this seems kinda stupid. Is there a more suitable method for saving the information in like 1 array, and just pass part of the data to the tableview?

    Read the article

  • PHP arrays & keys - fetching particular ones

    - by Rohan
    Hi Lets say I have an array with a structure like this: $arr= Array( array( "id"=>"a" "type">"apple"), array( "id"=>"b"), array( "id"=>"c"), array( "id"=>"c" "type"=>"banana") ); now I want to have a foreach loop which fetches all the array elements which have a key in them named "type". Something like foreach(all arrays which have type in them as $item) How would I do that? many thanks.

    Read the article

  • Generic arrays of parametrized ArrayLists in java?

    - by athena123
    I am new to Java, so I am not aware of the nitty gritties. Why can't I create generic array of parametrized ArrayList? Instead I have to write, ArrayList<String>[] alist = new ArrayList[10]; or I have to create List of ArrayLists. Aren't arrays supposed to be more efficient than ArrayLists? Then why doesn't Java allow it? Also, what is the difference between following two lines. ArrayList<String>[] alist = new ArrayList[10]; ArrayList<String>[] alist = new ArrayList<?>[10];

    Read the article

  • Faster way of initializing arrays in Delphi

    - by Max
    I'm trying to squeeze every bit of performance in my Delphi application and now I came to a procedure which works with dynamic arrays. The slowest line in it is SetLength(Result, Len); which is used to initialize the dynamic array. When I look at the code for the SetLength procedure I see that it is far from optimal. The call sequence is as follows: _DynArraySetLength - DynArraySetLength DynArraySetLength gets the array length (which is zero for initialization) and then uses ReallocMem which is also unnecessary for initilization. I was doing SetLength to initialize dynamic array all the time. Maybe I'm missing something? Is there a faster way to do this?

    Read the article

  • writing a single line of a file in C++ into two different arrays

    - by mekasperasky
    suppose a text file has 11001100 11001101 and i open the text file and take the input from the file as pt[0]=11001100, pt[1]=11001101.. but if i take the input from file as inpt it wont put it in two different arrays which is obvious but it takes the whole line . Thus I have to take another for loop and traverse through the whole string and when I find a null character i start putting into the second array . But how can I do it without putting it into a variable and traversing .. I mean directly from the file itself ..

    Read the article

  • Divide a array into multiple (individual) arrays based on a bin size in python

    - by user1492449
    I have an array like this: -0.68285 -6.919616 -0.7876 -14.521115 -0.64072 -43.428411 -0.05368 -11.561341 -0.43144 -34.768892 -0.23268 -10.793603 -0.22216 -50.341101 -0.41152 -90.083377 -0.01288 -84.265557 -0.3524 -24.253145 How do i split this array into individual arrays based on the value in column 1 with a bin width of 0.1? i want my output something like this: array1=[[-0.05368, -11.561341],[-0.01288, -84.265557]] array2=[[-0.23268, -10.79360] ,[-0.22216, -50.341101]] array3=[[-0.3524, -24.253145]] array4=[[-0.43144, -34.768892], [-0.41152, -90.083377]] array5=[[-0.68285, -6.919616],[-0.64072, -43.428411]] array6=[[-0.7876, -14.521115]]

    Read the article

  • F# &ndash; Immutable List vs a Mutable Collection in Arrays

    - by MarkPearl
    Another day gone by looking into F#. Today I thought I would ramble on about lists and arrays in F#. Coming from a C# background I barely ever use arrays now days in my C# code – why you may ask – because I find lists generally handle most of the business scenario’s that I come across. So it has been an interesting experience with me keep bumping into Array’s & Lists in F# and I wondered why the frequency of coming across arrays was so much more in this language than in C#. Take for instance the code I stumbled across today. let rng = new Random() let shuffle (array : 'a array) = let n = array.Length for x in 1..n do let i = n-x let j = rng.Next(i+1) let tmp = array.[i] array.[i] <- array.[j] array.[j] <- tmp array   Quite simply its purpose is to “shuffle” an array of items. So I thought, why does it have the “a’ array'” explicitly declared? What if I changed it to a list? Well… as I was about to find out there are some subtle differences between array’s & lists in F# that do not exist in C#. Namely, mutability. A list in F# is an ordered, immutable series of elements of the same type, while an array is a fixed-size zero based, mutable collection of consecutive data elements that are all of the same type. For me the keyword is immutable vs mutable collection. That’s why I could not simply swap the ‘a array with ‘a list in my function header because then later on in the code the syntax would not be valid where I “swap” item positions. i.e. array.[i] <- array.[j] would be invalid because if it was a list, it would be immutable and so couldn’t change by its very definition.. So where does that leave me? It’s to early days to say. I don’t know what the balance will be in future code – will I typically always use lists or arrays or even have a balance, but time will tell.

    Read the article

  • Multi-Array of XML Requests

    - by sologhost
    OMG, I am in need of a way to set up arrays of XML Requests based on the idShout - 1. So it would be something like this... var req = new Array(); req[idShout - 1] = ALL XML Data... Here's what I got so far but it's not working at all :( var idShout; var req = new Array(); function htmlRequest(url, params, HttpMethod) { req[req.push] = ajax_function(); for (i=0;i<req.length;i++) { if (req[i]) { if (HttpMethod == "GET") { req[i].onreadystatechange = function() { if (req[i].readyState != 4) return; if (req[i].responseText !== null && req[i].status == 200) { document.getElementById("shoutbox_area" + idShout).innerHTML = req[i].responseText; } } } req[i].open(HttpMethod,url,true); if (HttpMethod == "POST") req[i].setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (params == "") req[i].send(null); else req[i].send(params); return req[i]; } else return null; } } function ajax_function() { var ajax_request = null; try { // Opera 8.0+, Firefox, Safari ajax_request = new XMLHttpRequest(); } catch (e) { // IE Browsers try { ajax_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajax_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { //No browser support, rare case return null; } } } return ajax_request; } function send() { var send_data = "shoutmessage=" + document.getElementById("shout_message" + idShout).value; var url = smf_prepareScriptUrl(smf_scripturl) + "action=dreamaction;sa=shoutbox;xml;send_shout="+ idShout; htmlRequest(url, send_data, "POST"); document.getElementById("shout_message" + idShout).value = ""; document.getElementById("shout_message" + idShout).focus(); return true; } function startShouts(refreshRate, shoutCount) { clearInterval(Timer[shoutCount-1]); idShout = shoutCount; show_shouts(); Timer[shoutCount - 1] = setInterval("show_shouts()", refreshRate); return; } function show_shouts() { var url = smf_prepareScriptUrl(smf_scripturl) + "action=dreamaction;sa=shoutbox;xml;get_shouts=" + idShout; htmlRequest(url, "", "GET"); } Any help at all on this would be greatly appreciated... Basically, I'm setting the Timer Arrays in a different function before this, and I call startShouts which is supposed to show all of the information, but startShouts gets called more than once, which is why I have idShout set to equal shoutCount. So it will go something like this: shoutCount = 1, shoutCount = 2, shoutCount = 3, everytime it is being called. So I set the req[idShout - 1] array and it should return the result right?? Well, I get no errors in Firefox in the error console with this code above, but it doesn't work... Any ideas anyone?? As it needs to output into more than 1 area... argg. Thanks for any help you can offer here :) Thanks guys :)

    Read the article

  • Explain the Peak and Flag Algorithm

    - by Isaac Levin
    EDIT Just was pointed that the requirements state peaks cannot be ends of Arrays. So I ran across this site http://codility.com/ Which gives you programming problems and gives you certificates if you can solve them in 2 hours. The very first question is one I have seen before, typically called the Peaks and Flags question. If you are not familiar A non-empty zero-indexed array A consisting of N integers is given. A peak is an array element which is larger than its neighbours. More precisely, it is an index P such that 0 < P < N - 1 and A[P - 1] < A[P] A[P + 1] . For example, the following array A: A[0] = 1 A[1] = 5 A[2] = 3 A[3] = 4 A[4] = 3 A[5] = 4 A[6] = 1 A[7] = 2 A[8] = 3 A[9] = 4 A[10] = 6 A[11] = 2 has exactly four peaks: elements 1, 3, 5 and 10. You are going on a trip to a range of mountains whose relative heights are represented by array A. You have to choose how many flags you should take with you. The goal is to set the maximum number of flags on the peaks, according to certain rules. Flags can only be set on peaks. What's more, if you take K flags, then the distance between any two flags should be greater than or equal to K. The distance between indices P and Q is the absolute value |P - Q|. For example, given the mountain range represented by array A, above, with N = 12, if you take: two flags, you can set them on peaks 1 and 5; three flags, you can set them on peaks 1, 5 and 10; four flags, you can set only three flags, on peaks 1, 5 and 10. You can therefore set a maximum of three flags in this case. Write a function that, given a non-empty zero-indexed array A of N integers, returns the maximum number of flags that can be set on the peaks of the array. For example, given the array above the function should return 3, as explained above. Assume that: N is an integer within the range [1..100,000]; each element of array A is an integer within the range [0..1,000,000,000]. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modified. So this makes sense, but I failed it using this code public int GetFlags(int[] A) { List<int> peakList = new List<int>(); for (int i = 0; i <= A.Length - 1; i++) { if ((A[i] > A[i + 1] && A[i] > A[i - 1])) { peakList.Add(i); } } List<int> flagList = new List<int>(); int distance = peakList.Count; flagList.Add(peakList[0]); for (int i = 1, j = 0, max = peakList.Count; i < max; i++) { if (Math.Abs(Convert.ToDecimal(peakList[j]) - Convert.ToDecimal(peakList[i])) >= distance) { flagList.Add(peakList[i]); j = i; } } return flagList.Count; } EDIT int[] A = new int[] { 7, 10, 4, 5, 7, 4, 6, 1, 4, 3, 3, 7 }; The correct answer is 3, but my application says 2 This I do not get, since there are 4 peaks (indices 1,4,6,8) and from that, you should be able to place a flag at 2 of the peaks (1 and 6) Am I missing something here? Obviously my assumption is that the beginning or end of an Array can be a peak, is this not the case? If this needs to go in Stack Exchange Programmers, I will move it, but thought dialog here would be helpful. EDIT

    Read the article

  • Rearrange array

    - by bradenkeith
    Array starts like this: Array ( [SMART Board] => Array ( [0] => sb1 [1] => sb2 [2] => sb3 ) [Projector] => Array ( [0] => pr1 [1] => pr2 [2] => pr3 ) [Speakers] => Array ( [0] => sp1 [1] => sp2 [2] => sp3 ) [Splitter] => Array ( [0] => spl1 [1] => spl2 [2] => spl3 ) [Wireless Slate] => Array ( [0] => ws1 [1] => ws2 [2] => ws3 ) ) The keys are used as my table columns titles. Their individual arrays are to carry the column information. I have split it up even further with array_slice and array_merge_recursive to look pretty as 2 arrays - 1 holds the column names, the other looks like this: Array ( [0] => sb1 [1] => sb2 [2] => sb3 [3] => pr1 [4] => pr2 [5] => pr3 [6] => sp1 [7] => sp2 [8] => sp3 [9] => spl1 [10] => spl2 [11] => spl3 [12] => ws1 [13] => ws2 [14] => ws3 ) However, when trying to write the table I'm getting keys 0, 1, 2 as the column data, then row break then 3, 4, 5 then row break... etc. I need it to be 0, 3, 6, 9, 12 row break 1, 4, 7, 10, 13 row break etc... How can I either rearrange my array to allow for this, or rewrite how the data goes into the table so that the correct information lines up with the appropriate column? foreach(unserialize($dl->data) as $data){ //first 3 are specialinstructions, system, and room $uniques = array_slice($data,0,3); $rows = array_slice($data,3); $rows2 = array_merge_recursive($rows2, $rows); //get the specialinstructions, system, and room foreach($uniques as $unique){ echo $unique."<br/>"; }///foreach uniques echo "<br>"; }///foreach unserialized $numberofrooms = count($rows2[key($rows2)]); $numberofproducts = count($rows2); print_r($rows2); unset($rows); //write the individual rows foreach($rows2 as $header=>$rowset){ $headers[] = $header; foreach($rowset as $row){ $rows[] = $row; }//foreach rowset }//foreach rows2 echo "<p>"; print_r($rows); echo '<table class="data-table"> <caption>DL</caption> <thead><tr>'; foreach($headers as $header){ echo "<th>".$header."</th>"; } echo '</tr></thead>'; echo '<tbody>'; $i = 0; foreach($rows as $row){ if($i == 3 || $i == 0){ echo "<tr>"; $i = 1; } echo '<td>'.$row.'</td>'; if($i == 2){ echo "</tr>"; } $i++; } echo '</tbody></table>';

    Read the article

< Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >