This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Ruban</title> | |
<meta charset="utf-8" /> | |
<link rel="stylesheet" href="bower_components/normalize-css/normalize.css" /> | |
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css" /> | |
<link rel="stylesheet" href="bower_components/highlightjs/styles/tomorrow.css" /> | |
<link rel="stylesheet" href="bower_components/ruban/css/ruban.min.css" /> | |
<link rel="stylesheet" href="bower_components/ruban/css/ruban-print.min.css" media="print" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
answersDidChange: Ember.on('init', Ember.observer('answers', function() { | |
// some side effect of salutation changing | |
console.log('answers changed to ' + this.get('answers')); | |
})), | |
didInsertElement: function() { | |
console.log('answers ' + this.get('answers')); | |
let array = JSON.parse(this.get('answers')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (_(proposals).isEmpty()) return []; | |
if (_(proposals).isNotArrayOfString()) return []; | |
if (_(answers).isNotArrayOfBoolean()) return []; | |
if (_(answers).size() > _(proposals).size()) return []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function labeledCheckboxes (proposals, answers) { | |
// check pre-conditions | |
if (_(proposals).isEmpty()) return []; | |
if !(_(proposals).isArray && _.every(proposals, _.isString)) return []; | |
if !(_(proposals).isArray && _.every(proposals, _.isBoolean)) return []; | |
if (_(answers).size() > _(proposals).size()) return []; | |
// etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check pre-conditions | |
if (_(proposals).isEmpty()) return []; | |
if (_(proposals).isNotArrayOfString()) return []; | |
if (_(answers).isNotArrayOfBoolean()) return []; | |
if (_(answers).size() > _(proposals).size()) return []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function labeledCheckboxes (proposals, answers) { | |
let result = _.zip(proposals, answers); | |
result = _.map(result, (item) => { | |
if (item[1]) { | |
return [item[0], true]; | |
} else { | |
return [item[0], false]; | |
} | |
}); | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Example : | |
* => Input : | |
* proposals : ['is sky red ?' , 'is sun red ?' , 'is grass red ?' , 'is cloud red ?'] | |
* => Input : | |
* userAnswers : [false, true] | |
* | |
* WARNING : only first(s) userAnswers are given, | |
* all others have implicitly the boolean value "false" | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let result = _.zip(proposals, answers); | |
result = _.map(result, (item) => { | |
if (item[1]) { | |
return [item[0], true]; | |
} else { | |
return [item[0], false]; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sizeDifference = _(proposals).size() - _(answers).size(); | |
const arrayOfFalse = _.times(sizeDifference, _.constant(false)); | |
return _.chain(answers) | |
.concat(arrayOfFalse) | |
.zip(proposals) | |
.map(_.reverse) | |
.value(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sizeDifference = _(proposals).size() - _(userAnswers).size(); // 2 | |
const completeWithFalse = _.times(sizeDifference, _.constant(false)); // [false, false] | |
return _.chain(userAnswers) // [false, true] | |
.concat(completeWithFalse) // [false, true, false, false] | |
.zip(proposals) // [[false, 'prop 1'], [true, 'prop 2'], [false, 'prop 3'], [false, 'prop 4']] | |
.map(_.reverse) // [['prop 1', false], ['prop 2', true], ['prop 3', false], ['prop 4', false]] | |
.value(); |
OlderNewer