Ad
Fundamentals
Arrays
Code
Diff
  • function Sum-OfPositive($NumberArray)
    {
    ( $NumberArray | where{$_ -gt 0} | Measure-Object -sum).Sum
    }
    
    • function SumOfPositive($NumberArray)
    • function Sum-OfPositive($NumberArray)
    • {
    • ( $NumberArray | where{$_ -gt 0} | Measure-Object -sum).Sum
    • }
Fundamentals
Arrays
Code
Diff
  • function SumOfPositive($NumberArray)
    {
    ( $NumberArray | where{$_ -gt 0} | Measure-Object -sum).Sum
    }
    
    • function Get-SumOfPositive($NumberArray)
    • function SumOfPositive($NumberArray)
    • {
    • $Sum =0;
    • foreach($Number in $NumbArray){
    • if($Number -gt 0){
    • $Sum+=$Number
    • }
    • }
    • Write-Output $Sum
    • ( $NumberArray | where{$_ -gt 0} | Measure-Object -sum).Sum
    • }

Create a simple calculator that given two numbers and an operator returns the value of the arithmetic operation. Here are the operations to support:

    • addition
    • subtraction
    • multiplication
Code
Diff
  • function Calculator ($n1,$s,$n2 ){
      Invoke-Expression ("$n1  $s  $n2")
    }
    • import javax.script.ScriptEngineManager;
    • interface Calculator {
    • static int calculate(int a, int b, char operation) {
    • var engine = new ScriptEngineManager().getEngineByName("JavaScript");
    • try {
    • return Integer.parseInt(String.valueOf(engine.eval(a + " " + operation + " " + b)));
    • } catch (Exception cause) {
    • return 0;
    • }
    • }
    • }
    • function Calculator ($n1,$s,$n2 ){
    • Invoke-Expression ("$n1 $s $n2")
    • }
Code
Diff
  • "Hello PowerShell!"
    • #!/bin/bash
    • STR="Hello Bash!"
    • echo $STR
    • "Hello PowerShell!"