-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask-1.js
More file actions
34 lines (20 loc) · 832 Bytes
/
Task-1.js
File metadata and controls
34 lines (20 loc) · 832 Bytes
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
// Write a JavaScript code to reverse the array colors without using the reverse method.
let colors=['red', 'blue', 'green', 'yellow', 'orange'];
console.log(colors);
// const ColorsReversed= colors.reverse();
// console.log(ColorsReversed); but do not use reverse method
let Reverse_rev=[];
for(let i=colors.length-1; i>=0; i--){
Reverse_rev.push(colors[i]);
}
console.log(Reverse_rev);
// Task -4 Reverse the words of a sentence. Only the position of the word will be reversed. check out the output
const statement = 'I am a hard working person But I love to relax';
let words = statement.split(' ');
// console.log(words);
let reversedWords= [];
for (let i = words.length - 1; i >= 0; i--) {
reversedWords.push(words[i]);
}
let reversedStatement = reversedWords.join(' ');
console.log(reversedStatement);