Sha256: 0edb916aa879754b8c933ff6121790ea7443c36accbae840004eadddf85aa53a

Contents?: true

Size: 678 Bytes

Versions: 37

Compression:

Stored size: 678 Bytes

Contents

import 'dart:math' show pow;

class ArmstrongNumbers {
  /// The parameters and variables within the method that are set to final in order to prevent the accidentally modification of the value.
  /// As those variables are not needed to be changed.
  bool isArmstrongNumber(final int number) {
    final String numberAsString = number.toString();
    final int numOfDigits = numberAsString.length;
    int sum = 0;

    for (int count = 0; count < numOfDigits; count++) {
      final String digitAsString = numberAsString.substring(count, count + 1);
      final int digit = int.parse(digitAsString);
      sum += pow(digit, numOfDigits);
    }

    return number == sum;
  }
}

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.179 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.178 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.177 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.176 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.175 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.174 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.173 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.172 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.171 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.170 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.169 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.167 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.166 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.165 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.164 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.163 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.162 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.161 tracks/dart/exercises/armstrong-numbers/lib/example.dart
trackler-2.2.1.160 tracks/dart/exercises/armstrong-numbers/lib/example.dart