AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



javascript-array: Develop a program that builds a vector

The real matrix is given - X (n, n), n <= 15. Develop a program that builds a vector Y (n) according to the rule: Y (i) and is equal to the sum of the modules of those elements that are placed along the first including the negative element of the i-th row. If there is no negative element in the ith row, then Y (i) = -1.

javascript x 32
array x 12
Posted On : 2018-03-06 11:53:21.0
profile Aryan Gupta - anyforum.in Aryan Gupta
1900
up-rate
2
down-rate

Answers


<html>
<title>Vector Sum- anyforum.in</title>
<script type="text/javascript">
function getSumVector(matrix){
var n=matrix.length;
var newArray=[];
for(var i=1;i<=n;i++){
if(matrix[i-1].some(v => v < 0))
newArray[i-1]= matrix[i-1].reduce((a, b) => Math.abs(a) + Math.abs(b), 0);
else
newArray[i-1]= -1;
}
return newArray;
}
</script>
<body>
Vector of matrix [[1, 10, -2],[2,3,-4],[6,7,8]]) is: <script type="text/javascript">document.write(getSumVector([[1, 10, -2],[2,3,-4],[6,7,8]]).toString())</script>
</body>
</html>

Posted On : 2018-03-11 16:42:14
Satisfied : 3 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523186220855
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in