This blog post aim to start the development environment with Angular as quickly as possible.
Prerequisites
Install npm and node latest versions In my computer, node version : v8.10.0, npm version : 3.5.2
Install angular cli. Use below command to install angular cli. npm install -g @angular/cli My Angular CLI version : 6.1.2. Type ng -v to see angular CLI version.
Install visual code editor. This editor is great tool with lot of helper plugins to start with angular development.
Now time to create new angular project!
1. Type below command to create a new project called test-app
ng new test-app
This will create basic project scaffolding to start with. Now go to test-app folder and start a development server from there
1. Check whether the last digit of the integer can be divided by 2 or not
2. Check whether the sum of all digits of the integer can be divided by 3 or not
3. Check whether the last digit of the integer can be divided by 5 or not
4. If all the above checks fails Check whether there is an integer from 7 to square root of number which is divide the number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main
import (
"fmt"
"math"
"strconv"
)
func main() {
fmt.Printf("275489 is a prime : %t", isPrime(275489))
}
func isPrime(num int) bool {
if !canBeDivideBy2(num) && !canBeDivideBy3(num) && !canBeDivideBy5(num) {
isPrime := true
//If the number can not be divided by 2, 3 or 5 divide from 7 to squre root of the number to check the existence of a factor
for i := 7; i <= int(math.Sqrt(float64(num))); i++ {
if num%i == 0 {
isPrime = false
break
}
}
return isPrime
}
return false
}
// If the last digit can be divided by 2 whole number can be divided by 2
func canBeDivideBy2(num int) bool {
numAsStr := strconv.Itoa(num)
lastNum, _ := strconv.Atoi(string(numAsStr[len(numAsStr)-1]))
return lastNum%2 == 0
}
// If the digit sum can be divided by 3 whole number can be divided by 3
func canBeDivideBy3(num int) bool {
numAsStr := strconv.Itoa(num)
sum := 0
for i := 0; i < len(numAsStr); i++ {
iThNum, _ := strconv.Atoi(string(numAsStr[i]))
sum += iThNum
}
return sum%3 == 0
}
//If the last digit can be divided by 5 whole number can be divided by 5
func canBeDivideBy5(num int) bool {
numAsStr := strconv.Itoa(num)
lastNum, _ := strconv.Atoi(string(numAsStr[len(numAsStr)-1]))
return lastNum%5 == 0
}