Browse Source

add JS `is the number a repdigit` task

Ethosa 3 years ago
parent
commit
5ca0001a70
2 changed files with 31 additions and 0 deletions
  1. 18 0
      Languages/js-rush/task6/main.js
  2. 13 0
      Languages/js-rush/task6/readme.md

+ 18 - 0
Languages/js-rush/task6/main.js

@@ -0,0 +1,18 @@
+function main() {
+    console.log(isRepdigit(66))
+    console.log(isRepdigit(0))
+    console.log(isRepdigit(-11))
+}
+
+function isRepdigit(num) {
+    if (num < 0)
+        return false
+    var str = num.toString()
+    Array(str).forEach( function(elem, i) {
+        if (elem != str[0])
+            return false
+    })
+    return true
+}
+
+main()

+ 13 - 0
Languages/js-rush/task6/readme.md

@@ -0,0 +1,13 @@
+# Is the Number a Repdigit
+
+## A repdigit is a positive number composed out of the same digit. Create a function that takes an integer and returns whether it's a repdigit or not.
+
+### Examples
+```js
+isRepdigit(66) ➞ true
+isRepdigit(0) ➞ true
+isRepdigit(-11) ➞ false
+```
+
+### Notes
+- The number `0` should return `true` (even though it's not a positive number).