2
votes
3answers
71 views

add element to ordered array in CoffeeScript

I have a sorted array, which I add elements to as the server gives them to me. The trouble I'm having is determining where to place my new element and then placing it in the same loop in javascript ...
1
vote
2answers
53 views

Swapping array elements in coffeescript

I'm learning coffeescript and wrote the following function to reverse a given word: reverse = (word) -> if word.length is 0 return "empty string" if word.length is 1 return word left ...
0
votes
3answers
53 views

Efficiently break an array every X number of values?

I want to split an array into a group of values starting at the end and leaving the beginning as a remander array. Here's an example of the goal: arr = [0,1,2,3,4,5,6,7,8,9,10,11] interval = 5 #chop ...
0
votes
2answers
56 views

how to run function in coffeescript for loop

I write coffeescript like this: split_typer_text = typer_text.split '' test = (char) -> setTimeout (-> element.text(element.text() + char)), 100 test char for char in split_typer_text but ...
0
votes
2answers
244 views

Coffeescript, array length undefined

Could anyone explain me why the length is always null? jsCountries = 0: country: "Brazil" photo: "source.png" alert jsCountries.length
1
vote
4answers
189 views

How to convert not nested JSON into nested HTML list in Javascript (or Coffeescript)?

I have some JSON data (simple array of objects) . var input= [ { "cat": "some", "id": "0" }, { "cat": "some", "id": "1" }, { "cat": ...
0
votes
3answers
101 views

Determining whether one array contains the contents of another array in JavaScript/CoffeeScript [duplicate]

In JavaScript, how do I test that one array has the elements of another array? arr1 = [1, 2, 3, 4, 5] [8, 1, 10, 2, 3, 4, 5, 9].function_name(arr1) # => true
7
votes
2answers
159 views

How to create two arrays in the same loop with CoffeeScript?

I want to create two arrays b and c at the same time. I know two methods which can be able to achieve it. The first method is b = ([i, i * 2] for i in [0..10]) c = ([i, i * 3] for i in [0..10]) ...
0
votes
1answer
34 views

Are args and args[..] the same?

I'm reading optparse.coffee, and confused with the following line: args = args[..] What does that line do?
1
vote
3answers
66 views

Concatenating an array with itself

I'm trying to implement Array.repeat, so [3].repeat(4) // yields => [3, 3, 3, 3] ... and is driving me crazy. Tried with this: Array::repeat = (num)-> array = new Array for n in ...
-1
votes
2answers
152 views

Checking if an array has some items in coffeescript

Is there some method in coffeescript that returns true when an array has some items in it? Like method in ruby present?: [].present? true [1].present? false According to ...
0
votes
2answers
532 views

Coffeescript / Node.js: How to remove duplicate objects from an array of objects?

How can I turn this array of objects (which has some duplicate objects): items = [ { TYPEID: 150927, NAME: 'Staples', COLOR: 'Silver' }, { TYPEID: 1246007, NAME: 'Pencils', COLOR: ...
-1
votes
1answer
108 views

Trying to get a variable to equal an object from a set of objects…i think?

OK so the way i worded this question before must have been too convoluted so here is a simplified version: I have a variable which equals: { txid: ...
0
votes
1answer
98 views

Truly Bizarre behaviour from coffescript/javascript array of functions

My code seems to bring about some kind of quantum duel state in chrome, invoking a universe where functions turn into undefined upon being pushed to an array... spooky I'm building an array of ...
1
vote
2answers
81 views

CoffeeScript Adding object to an array

I have the following code: class Number number = null constructor: (num) -> number = num getNumber: -> number class Sequence numbers = [] constructor: -> addNumber: (n) -> ...
4
votes
2answers
497 views

Getting the last element of an array in CoffeeScript

Is there a quick (short, character wise) way to get the last element of an array (assuming the array is non-empty)? I usually do: last = array[array.length-1] or last = array[-1..][0]
6
votes
4answers
3k views

Getting the first and last element of an array in CoffeeScript

If say I have an array and I would to iterate through the array, but do something different to the first and last element. How should I do that? Taking the below code as example, how do I alert ...
0
votes
2answers
154 views

coffeescript array finding next position

I have an array setup like the following: services = ['times', 'food', 'messages', 'share'] And I would like to be able to pass into services 'times' and have it return the next position in the ...
3
votes
6answers
2k views

Get largest value in multi-dimensional array javascript or coffeescript

I have an array that looks like the following: array = [[1, 5], [4, 7], [3, 8], [2, 3], [12, 4], [6, 6], [4, 1], [3, 2], [8, 14]] What I need is the largest number from the first value of the ...
5
votes
4answers
742 views

Is there an idiomatic way to test array equality in Coffeescript?

The expression [1, 2, 3] == [1, 2, 3] evaluates to false in Coffeescript but is there a concise, idiomatic way to test array equality?
4
votes
1answer
983 views

Using indexOf in CoffeeScript

I'm using the following code in CoffeeScript: if elem in my_array do_something() Which compiles to this javascript: if (__indexOf.call(my_array, elem) < 0) { my_array.push(elem); } I can ...
1
vote
2answers
76 views

How to construct an array of objects programmatically

I want to construct an array of objects programmatically. The end result I am expecting is this [{"nickname":"xxx"},{"nickname":"yyy"},{"nickname":"zzz"}] This is my code @tagged_user_array = [] ...
0
votes
3answers
228 views

Best way to iterate over an array and call functions in coffeescript

I have this code in coffescript copy pages.template for pages in configFiles.pages That generates this code in java script var pages, _i, _len, _ref; _ref = configFiles.pages(function() {}); for ...
0
votes
1answer
279 views

coffeescript looping through array and adding values

What I'd like to do is add an array of students to each manager (in an array). This is where I'm getting stuck: for sup in sups do(sup) -> sup.students_a = "This one ...
6
votes
2answers
3k views

How do I sort an Array with coffeescript?

with an Array like this: users = [ { id: 1, fname: 'Fred', lname: 'Flinstone', state: 'CA' }, { id: 2, fname: 'George', lname: 'Winston', state: 'FL' }, { id: 3, fname: 'Luke', lname: ...
1
vote
2answers
104 views

How to select an object from an array where a certain property is minimal?

I'm just getting my head around Coffescript and have come across a requirement to select an object from an array where a particular property is minimal. I've set out my basic code below: class Point ...
0
votes
2answers
276 views

How to show 3 items in an array every time I click on button

I am using the code below to show only the first 3 items in an array as default //Hides all but first 3 items in the array @$('.question_container')[3..-1].hide() Now, I want to display the next 3 ...
0
votes
1answer
869 views

How to push to an array in a particular position?

I'm trying to efficiently write a statement that pushes to position 1 of an array, and pushes whatever is in that position, or after it back a spot. array = [4,5,9,6,2,5] #push 0 to position 1 ...
0
votes
2answers
75 views

Splicing the wrong element(s)

I have an array of comments. Some of these comments are actually subcomments of other nodes within comments. Every comment has a num_comments, parent_id, and id attribute. I know a comment has ...
4
votes
3answers
1k views

CoffeeScript “Array()” vs “new Array()”

what is the difference (if there is any) between x = Array() and x = new Array() in CoffeeScript (or JavaScript for that purpose)? Which one should I use?
0
votes
2answers
207 views

JS, How extend typed arrays subclassing ?? How to do it right?

I'm writing an library in CoffeScript (so JS), and it is heavy math.. I really need to work with typed arrays (Float64Array) and all the performance they offer. So what is the best way to extend the ...
3
votes
3answers
150 views

Why does setting positions in a subclass of Array not change its length? Should I not subclass array?

In the CoffeeScript program below, I create a subclass of Array which sets two positions in its constructor: class SetPositionsArray extends Array constructor: (x,y) -> @[0] = x @[1] = y ...
4
votes
2answers
564 views

CoffeeScript: How to return a array From class?

What is wrong in this class in CoffeeScript ?? @module "Euclidean2D", -> class @Point constructor: (x,y) -> return if Float32Array? then Float32Array([ x, y ]) else Array(x,y) I ...
23
votes
2answers
13k views

In CoffeeScript how do you append a value to an Array?

What is the proscribed way to append a value to an Array in CoffeeScript? I've checked the PragProg CoffeeScript book but it only discusses creating, slicing and splicing, and iterating, but not ...
12
votes
3answers
4k views

Concatenating an array of arrays in Coffeescript

I'm trying to find an elegant way in Coffeescript to merge an array of arrays, so that [[1,2,3],[4,5,6],[7,8,9]] ==> [1,2,3,4,5,6,7,8,9]. As you might imagine, I need this because I'm generating ...