Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save NishiBangar/66f4d0956c4992798d3885ba1ddb32de to your computer and use it in GitHub Desktop.

Select an option

Save NishiBangar/66f4d0956c4992798d3885ba1ddb32de to your computer and use it in GitHub Desktop.
Multiplication of Digits based on column counts
<html ng-app="myApp">
<body ng-controller="myController">
<div class="row">
<div class="col-sm-2">
<label for="" class="control-label">Enter Count</label>
</div>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="count" />
</div>
<button class="btn btn-success btn-sm" ng-click="calculateResult()" >Submit</button>
</div>
<div class="row" ng-repeat="item in finalArray">
<div class="col-sm-5">
<label class="control-label">{{item.label}}</label>
</div>
<div class="col-sm-2">
<label class="control-label">{{item.result}}</label>
</div>
</div>
</body>
</html>

Multiplication of Digits based on column counts

Multiplication of digits, such a way that, first column should include "Numbers in Ascending order" and the next should include "Number in Descending order". This pattern should be followed for the number of column counts.

Example : Count=2; 1 * 10 = 10 2 * 9 = 18 3 * 8 = 24 . . . . . . . . . . . . . . 10 * 1 = 10

Count=3; 1 * 10 * 1 = 10 2 * 9 * 2 = 18 3 * 8 * 3 = 24 . . . . . . . . . . . . . . . . . . . . 10 * 1 * 10 = 100

A Pen by Nishchith J Bangar on CodePen.

License.

var myApp=angular.module("myApp",[]);
myApp.controller("myController",['$scope',function($scope){
$scope.array=[1,2,3,4,5,6,7,8,9,10];
$scope.count=0;
$scope.finalArray=[];
$scope.ascNum=[1,2,3,4,5,6,7,8,9,10];
$scope.descNum=[10,9,8,7,6,5,4,3,2,1];
$scope.calculateResult=function(){
$scope.finalArray=[];
console.log(parseInt($scope.count));
if(parseInt($scope.count)>0){
for(var j=0;j<10;j++){
var item={"label":"","result":1};
for(var i=0;i<parseInt($scope.count);i++){
// console.log(parseInt($scope.count)%2==0);
if(i%2==0){
console.log("ascNum = "+i);
item.label=item.label+" * "+$scope.ascNum[j]; item.result=item.result*$scope.ascNum[j];
}
else{
console.log("descNum = "+i);
item.label=item.label+" * "+$scope.descNum[j];
item.result=item.result*$scope.descNum[j];
}
}
console.log(item.label.slice(3));
item.label=item.label.slice(3)+" = ";
$scope.finalArray.push(item);
}
}
};
}]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment