Example #1
0
function notScoredByCitizen(bills, citizenId, billId) {
  var out = array(bills).select(function (l) {
    return !l.userScored;
  }).toArray();

  if (array(out).find({ id: billId })) {
    out = putFirst(out, billId);
  }

  return out;
}
Example #2
0
    return this._fetch(token, n, m).then(json => {
      this._add_notes(json.data);

      if(json.mark && this.notes.length < len) {
        return this._get(token, len, json.mark);
      } else {
        this.notes = array(this.notes).sort('modifydate', 'desc');
        return this.notes;
      }
    });
Example #3
0
    function(err, results){
      if(err) throw err;

      console.log("- Done");
      // Example
      // +---------------------------------------------------------------+
      // | mm.tweetId           | p.zh_title | p.en_title | m.id         |
      // +---------------------------------------------------------------+
      // | "161919961135198208" | "测试"       | "Test"     | "mexHWuM5YG" |
      // | "161886356124090369" | "测试"       | "Test"     | "mexHWuM5YG" |
      // | "163261433872777216" | "测试"       | "Test"     | "mexHWuM5YG" |
      // | "162164581257588736" | "测试"       | "Test"     | "mexHWuM5YG" |
      // | "162095413221015552" | "测试"       | "Test"     | "mexHWuM5YG" |
      // | "163097486909636608" | "测试"       | "Test"     | "mexHWuM5YG" |
      // | "163436071835811841" | "测试"       | "Test"     | "mexHWuM5YG" |
      console.log("Counting links");
      var processedId = {};
      var pages = {};
      for (var i = 0; i < results.length; i++) {
        var row = results[i];
        var title = row.enTitle + ", " + row.zhTitle;
        if(!pages[title]) pages[title] = {tweet: 0, weibo: 0};

        var tweetIdKey = title + row.tweetId;
        if(!processedId[tweetIdKey]){
          processedId[tweetIdKey] = true;
          pages[title].tweet += 1;
        }

        var weiboIdKey = title + row.weiboId;
        if(!processedId[weiboIdKey]){
          processedId[weiboIdKey] = true;
          pages[title].weibo += 1;
        }
      }

      console.log("Generating CSV");
      var csvTitle = "en_title, zh_title, tweet_links, weibo_links";
      var csvLines = [];
      for (var title in pages) {
        var line = title;
        line += ", " + pages[title].tweet + ", " + pages[title].weibo;
        csvLines.push(line);
      }
      var array = require("array");
      csvLines = array(csvLines).sort();

      var csvContent = csvTitle + "\n" + csvLines.join("\n");
      var fs = require("fs");
      fs.writeFileSync("tmp/links.csv", csvContent);

      console.log("Done");
    }
Example #4
0
BillProposalViewer.prototype.reload = function() {

  this.bills = putFirst(randomize(laws.get()), this.lawId);
  this.selected = this.bills[0];

  // sort & select properly if user is logged in
  if (citizen.logged()) {
    this.bills = sortForCitizen(this.bills, citizen.id, this.lawId);

    if (this.lawId) {
      this.selected = array(this.bills).find({ id: this.lawId});
    } else {
      this.selected = notScoredByCitizen(this.bills, citizen.id, this.lawId)[0];
    }

    // Only if user is logged in and nothing remains unvoted
    if (!this.selected) {
      page('/gracias');
      return;
    }

    // just in case everything is voted
    this.selected = this.selected || array(this.bills).last();
  }

  this.container = this.find('.bill-proposal-container');
  this.container.empty();

  this.bills.forEach(this.add);
  this.carousel = new Carousel(this.container[0]);
  var el = this.find('.bill-proposal[data-id="' + this.selected.id + '"');
  if (el.length) {
    this.carousel._show(el[0]);
  }

  // Update progress bar
  this.updateProgress(this.bills.indexOf(this.selected) + 1);
};
Example #5
0
function putLast (bills, billId) {
  if (!billId) return bills;

  var arr = array(bills);

  var b = arr.find( { id: billId });

  if (!b) return arr.toArray()

  arr = arr.reject(function (val) {
    return val.id == b.id;
  });

  return arr.toArray().concat([b]);
}
Example #6
0
var eleve= require('./dorra.js');

console.log(eleve.nom);
console.log(eleve.prenom);


var unique = require('uniq');

var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];  //eviter la repition

console.log(unique(data));

var array = require('array'),
    users = array([1,2,3,4,5,6]);
    var chaine=users.join(chaine);
    console.log(chaine);
    var users1=users.slice(1,4);
    console.log(users1);
    var chaine1=users.toString();
    console.log(chaine1);
    users.pop();
    chaine=users.toString();
    console.log(chaine);
    users.reverse();
    chaine=users.toString();
    console.log(chaine);



var ecole={
  nbrEleve: 500,