Repository navigation
Expand file tree
/
Copy pathShuffleArray.js
More file actions
74 lines (70 loc) · 2.32 KB
/
Copy pathShuffleArray.js
File metadata and controls
74 lines (70 loc) · 2.32 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const shuffleArray = array => {
/*Purpose of this function is to return a shuffled version of the numbers checks to see if array is an array
Also checks that values 1 - 9 is in the array needed for this program.
*/
let valid = false;
// let valid = false;
Array.isArray(array)
? (valid = true)
: console.error(
"Type Error :Unexpected Type argument should be an array line 19"
);
array.length === 9
? (valid = true)
: console.error(
"Type Error : Unexpected Length argument should be length 9 line 20"
);
array.includes(1)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 1 line 21"
);
array.includes(2)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 2 line 22"
);
array.includes(3)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 3 line 23"
);
array.includes(4)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 4 line 24"
);
array.includes(5)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 5 line 25"
);
array.includes(6)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 6 line 26"
);
array.includes(7)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 7 line 27"
);
array.includes(8)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 8 line 28"
);
array.includes(9)
? (valid = true)
: console.error(
"Type Error : Value missing array should include the integer 9 line 29"
);
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return [array, valid];
};
export default shuffleArray;