Posts

Showing posts with the label repeat

Repeating td tags inside a repeating tr tag in react

Image
Clash Royale CLAN TAG #URR8PPP Repeating td tags inside a repeating tr tag in react Hi i've been trying to do the following in react but I get this error: Uncaught Error: Objects are not valid as a React child (found: object with keys {id, address, long, lat, cityId, cityDistrict, phone, name, userId, city}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of Comparison . Comparison this is my code: let comparedProperties = { id: [1001,1002], address: ["abc","def"], }; let comparedItemsData = ; for (var key in comparedProperties) { if (comparedProperties.hasOwnProperty(key)) { let newTDs = ; let newTR = <tr key={Math.random()} className="compare-table-row"> <td className="table-item-header"> {key} ...

Writing a string repeater in C produces unwanted chars

Image
Clash Royale CLAN TAG #URR8PPP Writing a string repeater in C produces unwanted chars I'm trying to get a custom string repeater to work in C. It works for some input, and in other cases it appends unwanted characters. It seem to me malloc in some cases allocates too much memory, but I don't quite grasp why. malloc Examples: repeater("hi", 2) -> hihi repeater("hi", 2) -> hihi repeater("yeah", 4) -> yeahyeahyeahyeah?f{?? repeater("yeah", 4) -> yeahyeahyeahyeah?f{?? The code: int length(char* str) { int i; if(str == NULL) return 0; for(i = 0; *(str+i) != ''; ++i); return i; } char* repeater(char* str, int times) { char* out; int i,len,sz; len = length(str); sz = len * times; out = (char*)malloc(sz * sizeof(char)); for(i = 0; i < sz; i++) *(out+i) = *(str + (i % len)); return out; } By clic...