JSFiddle - React, Tailwind, and code Playground
by Amulya Kashyap
HTML
<legend> Enter Speed</legend>
<input type="text" ng-model="speed.value" required />
<button type="button" ng-click="calc()">Get Animal</button>
<span>{{filteredAnimals}}</span>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function($scope) {
$scope.animals = [
{
"speed": 33.7,
"animal": 'pig',
},
{
"speed": 40.2,
"animal": 'Dog',
},
{
"speed": 45.4,
"animal": 'Horse',
}];
$scope.calc = function(){
$scope.curSpeed = parse.Int($scope.speed.value);
var len = $scope.animals.length - 1;
var filteredAnimals;
while(len >= 0){
if($scope.curSpeed >= $scope.animals[len].speed){
filteredAnimals = $scope.filteredAnimals = $scope.animals[len].animal;
break;
}
len--;
}
}
});