FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/String/CheckExceeding.js at master · TheAlgorithms/JavaScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TheAlgorithms
/
JavaScript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
5.8k
Star
34.2k
Code
Issues
21
Pull requests
192
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
String
/
CheckExceeding.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (32 loc) · 1.27 KB
Breadcrumbs
JavaScript
/
String
/
CheckExceeding.js
Copy path
File metadata and controls
40 lines (32 loc) · 1.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
*
@function
checkExceeding
*
@description
- Exceeding words are words where the gap between two adjacent characters is increasing. The gap is the distance in ascii
*
@param
{
string
} str
*
@returns
{
boolean
}
*
@example
- checkExceeding('delete') => true, ascii difference - [1, 7, 7, 15, 15] which is incremental
*
@example
- checkExceeding('update') => false, ascii difference - [5, 12, 3, 19, 15] which is not incremental
*/
const
checkExceeding
=
(
str
)
=>
{
if
(
typeof
str
!==
'string'
)
{
throw
new
TypeError
(
'Argument is not a string'
)
}
const
upperChars
=
str
.
toUpperCase
(
)
.
replace
(
/
[
^
A
-
Z
]
/
g
,
''
)
// remove all from str except A to Z alphabets
const
adjacentDiffList
=
[
]
for
(
let
i
=
0
;
i
<
upperChars
.
length
-
1
;
i
++
)
{
// destructuring current char & adjacent char by index, cause in javascript String is an object.
const
{
[
i
]
:
char
,
[
i
+
1
]
:
adjacentChar
}
=
upperChars
if
(
char
!==
adjacentChar
)
{
adjacentDiffList
.
push
(
Math
.
abs
(
char
.
charCodeAt
(
)
-
adjacentChar
.
charCodeAt
(
)
)
)
}
}
for
(
let
i
=
0
;
i
<
adjacentDiffList
.
length
-
1
;
i
++
)
{
const
{
[
i
]
:
charDiff
,
[
i
+
1
]
:
secondCharDiff
}
=
adjacentDiffList
if
(
charDiff
>
secondCharDiff
)
{
return
false
}
}
return
true
}
export
{
checkExceeding
}
Back
|
FazBrowse Home
|
New Git URL