/categories/javascript/index.xml

Enum Methods comparison in Ruby/ Javascript and Elixir

Enum Methods comparison in Ruby/ Javascript and Elixir

all?

The all? method in Ruby returns a boolean value (true/false) if all the objects in the list either return true or satisfies the block condition.

Ruby

Enumerable#all?

No block:

>> [ true, "dog", "bear", 19 ].all?
=> true
>> [ nil, true, "hello" ].all?
=> false

With a block:

>> %w(cat dog squirrel bear).all? { |word| word.length >= 3 }
=> true
>> %w(cat dog squirrel bear).all? { |word| word.length <= 3 }
=> false

Elixir

Enum.all? No block:

>> Enum.all?([ true, "dog", "bear", 19 ])
true
>> Enum.all?([ nil, true, "hello" ])
false

With a block/fn:

>> Enum.all?(["cat", "dog", "squirrel", "bear"], fn word -> String.length(word) >= 3 end)
=> true
>> Enum.all?(["cat", "dog", "squirrel", "bear"], fn word -> String.length(word) <= 3 end)
=> false

Javascript

Array.prototype.every()

Only with callback support:

> [ true, "dog", "bear", 19 ].every(x => x)
true
> [null, true, "hello" ].every(x => x)
false

> ["cat", "dog", "squirrel", "bear"].every(word => word.length >= 3)
true
> ["cat", "dog", "squirrel", "bear"].every(word => word.length <= 3)
false

Read More

Minesweeper React Redux Screencast Tutorial - Parts 11-14

Looking for the game? Play It Here!

Final Episodes of my React/Redux Minesweeper Screencasts!

These are the final and maybe most interesting episodes of me live-coding a React/Redux version of Minesweeper. You can also checkout Part 1-5 and Part 6-10. These episodes aren’t as rough as I have improved my editing of the vidoes. You can also see the final source code.

React Redux Minesweeper Part 11 - Wiring up RESET_BOARD action to the game interface and building a GameMenu jsx/container pair.

Read More

Minesweeper React Redux Screencast Tutorial - Part 6-10

Looking for the game? Play It Here!

More Minesweeper built in React/Redux Screencasts - the journey continues!

As I mentioned in Part 1-5, a React/Redux version of Minesweeper is something I wanted to flush out. Creating these screencasts took longer than expected. They are very rough as I’m more or less live coding. Feel free to jump around to the parts you are most interested in and follow along with the source code.

React Redux Minesweeper Part 6 - Building actions in Reducers for opening a cell and flagging a cell.

Read More

Browserify-rails vs react-rails: Winner both

Browserify-rails vs  react-rails: Winner both

Recently, I have installed browserify-rails and react-rails together in the same Ruby on Rails project. This give the best of both worlds since I can still use the react_component helper provided by react-rails but use npm to manage my versions of different React.js components. However, if you install react-rails, make sure you do not run any of the generators.

Read More