Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team 4 #8

Open
pmaoui opened this issue Apr 27, 2016 · 1 comment
Open

Team 4 #8

pmaoui opened this issue Apr 27, 2016 · 1 comment

Comments

@pmaoui
Copy link

pmaoui commented Apr 27, 2016

/**
 * getHighestAndLowest: find the highest and lowest temperature from these thousands values
 * @temperatyres: parameter is an array
 */
function getHighestAndLowest(temperatures) {
    // Your code here
    var func = function(temperatures) {
      var lowestTemp = temperatures[0];
      var highestTemp = temperatures[temperatures.length - 1];

      for (var i=1, len = temperatures.length-1; i<len; i++) {
        if (lowestTemp.value > temperatures[i].value) {
          lowestTemp = temperatures[i]
        }
        if (highestTemp.value < temperatures[i].value) {
          highestTemp = temperatures[i]
        }
      }
      return { "lowestTemp":lowestTemp, "highestTemp": highestTemp }
    }
    var res = func(temperatures)

    return formatMyResult(res.lowestTemp.value, res.highestTemp.value);
}

/** DO NOT TOUCH THIS */

function formatMyResult(min, max) {
    return 'Les températures se situent entre ' + min + '°C et ' + max + '°C';
}

var request = require("request");

request({
    url: 'http://ns323481.ip-37-187-0.eu/coding/temperature10000.json',
    json: true
}, function (error, response, body) {

    if (!error && response.statusCode === 200) {
        console.time('temperatures'); 
        var result = getHighestAndLowest(response.body);
        console.timeEnd('temperatures');
        console.log('Result: ' + result);
    }
})

@pmaoui
Copy link
Author

pmaoui commented Apr 27, 2016

738ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant