7 kyu

Nice Array

2,960 of 6,948aweleshetu

Description:

A Nice array is defined to be an array where for every value n in the array, there is also an element n - 1 or n + 1 in the array.

examples:

[2, 10, 9, 3] is a nice array because

 2 =  3 - 1
10 =  9 + 1
 3 =  2 + 1
 9 = 10 - 1

[4, 2, 3] is a nice array because

4 = 3 + 1
2 = 3 - 1
3 = 2 + 1 (or 3 = 4 - 1)

[4, 2, 1] is a not a nice array because

for n = 4, there is neither n - 1 = 3 nor n + 1 = 5

Write a function named isNice/IsNice that returns true if its array argument is a Nice array, else false. An empty array is not considered nice.

Arrays
Mathematics
Fundamentals

Stats:

CreatedSep 12, 2017
PublishedSep 12, 2017
Warriors Trained11785
Total Skips381
Total Code Submissions44315
Total Times Completed6948
JavaScript Completions2960
C# Completions472
TypeScript Completions189
Python Completions2119
CoffeeScript Completions13
Crystal Completions11
Ruby Completions186
Julia Completions31
Dart Completions268
PHP Completions223
Java Completions729
COBOL Completions4
C Completions63
Total Stars130
% of votes with a positive feedback rating90% of 987
Total "Very Satisfied" Votes819
Total "Somewhat Satisfied" Votes142
Total "Not Satisfied" Votes26
Total Rank Assessments14
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • aweleshetu Avatar
  • zruF Avatar
  • Blind4Basics Avatar
  • Souzooka Avatar
  • KenKamau Avatar
  • monadius Avatar
  • hobovsky Avatar
  • benjamin.chang Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
Ad