-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathin_asc_order.php
More file actions
39 lines (35 loc) · 1.02 KB
/
in_asc_order.php
File metadata and controls
39 lines (35 loc) · 1.02 KB
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
<?php
// 7 kyu- Are the numbers in order?
//
// Are the numbers in order?
// In this Kata, your function receives an array of positive integers as input. Your task is to determine whether the numbers are in ascending order.
//
// For the purposes of this Kata, you may assume that all inputs are valid (i.e. arrays containing only positive integers with a length of at least 2).
//
// For example:
//
// in_asc_order([1, 2, 4, 7, 19]); // true
// in_asc_order([1, 2, 3, 4, 5]); // true
// in_asc_order([1, 6, 10, 18, 2, 4, 20]); // false
// in_asc_order([9, 8, 7, 6, 5, 4, 3, 2, 1]); // false (NOTE: because the numbers are in DESCENDING order, not ascending order) -->
function in_asc_order($arr) {
$arr1 = $arr;
$x = sort($arr);
return $x === $arr;
};
// Alternative Solution:
// function in_asc_order($arr) {
//
// $prev = $arr[0];
//
// foreach($arr as $key => $value) {
// if($prev > $value) return false;
// $prev = $value;
// }
//
// return true;
//
// };
$answer = in_asc_order([1,2,3]);
print_r("$answer \n");
?>