Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isSafeRow(data: number[]) {
- let inc = 0,
- dec = 0
- for (let i = 0; i < data.length - 1; i++) {
- if (data[i] > data[i + 1]) dec++
- else if (data[i] < data[i + 1]) inc++
- if (Math.abs(data[i] - data[i + 1]) > 3) {
- return false
- }
- }
- const len = data.length - 1
- if (inc === len || dec === len || inc === len - 1 || dec === len - 1) {
- return true
- }
- return false
- }
- function getTotalSafeRow(arr: Array<number[]>) {
- let total = 0
- for (let i = 0; i < arr.length; i++) {
- if (isSafeRow(arr[i])) {
- total++
- }
- }
- return total
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement