Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setValuesToIndexes(input, arr) {
- let n = Number(input[0]);
- for(let i = 0; i < n; i++){
- arr.push(0);
- }
- for(let i = 1; i < input.length; i++){
- let currentCommand = input[i].split(' - ');
- let index = Number(currentCommand[0]);
- let value = Number(currentCommand[1]);
- arr[index] = value;
- }
- for(let i = 0; i < arr.length; i++){
- console.log(arr[i]);
- }
- }
- let arr = [];
- let input = ['5', '0 - 3', '3 - -1', '4 - 2'];
- setValuesToIndexes(input, arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement