A simple 2-component ReactJS app

http://jsbin.com/linagikecu/edit?html,css,js,output

var ChildComponent = React.createClass({
    render: function() {
        return (
            <div>
                <button onClick={this.props.clickButton}>Click Me</button>
            </div>
        );
    }
});


var ParentComponent = React.createClass({
    performMagic: function() {
        alert('Hello There');
    },

    render: function() {
        return(
            <div>
                <ChildComponent clickButton={this.performMagic}/>
            </div>
        );
    }
});

ReactDOM.render(<ParentComponent/>, document.getElementById('app'));

Shuffle array in a class

This entry is part 33 of 41 in the series Swift

import UIKit

class ArrayObject : NSObject {
    
    var numbers = [1,2,3,4,5]
    
    func shuffleNumbers() {
        numbers.shuffle()
    }
}

extension MutableCollection where Indices.Iterator.Element == Index {
    /// Shuffles the contents of this collection.
    mutating func shuffle() {
        let c = count
        guard c > 1 else { return }
        
        for (unshuffledCount, firstUnshuffled) in zip(stride(from: c, to: 1, by: -1), indices) {
            let d: IndexDistance = numericCast(arc4random_uniform(numericCast(unshuffledCount)))
            guard d != 0 else { continue }
            let i = index(firstUnshuffled, offsetBy: d)
            swap(&self[firstUnshuffled], &self[i])
        }
    }
}

let array = ArrayObject()

array.shuffleNumbers()

print(array.numbers[1])